当前位置: 首页>>代码示例>>Python>>正文


Python pyearth.Earth类代码示例

本文整理汇总了Python中pyearth.Earth的典型用法代码示例。如果您正苦于以下问题:Python Earth类的具体用法?Python Earth怎么用?Python Earth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Earth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_export_python_string

def test_export_python_string():
    for smooth in (True, False):
        model = Earth(penalty=1, smooth=smooth, max_degree=2).fit(X, y)
        export_model = export_python_string(model, 'my_test_model')
        six.exec_(export_model, globals())
        for exp_pred, model_pred in zip(model.predict(X), my_test_model(X)):
            assert_almost_equal(exp_pred, model_pred)
开发者ID:Panadaren,项目名称:py-earth,代码行数:7,代码来源:test_export.py

示例2: test_pathological_cases

def test_pathological_cases():
    import pandas
    directory = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), 'pathological_data')
    cases = {'issue_44': {},
             'issue_50': {'penalty': 0.5,
                          'minspan': 1,
                          'allow_linear': False,
                          'endspan': 1,
                          'check_every': 1,
                          'sample_weight': 'issue_50_weight.csv'}}
    for case, settings in cases.iteritems():
        data = pandas.read_csv(os.path.join(directory, case + '.csv'))
        y = data['y']
        del data['y']
        X = data
        if 'sample_weight' in settings:
            filename = os.path.join(directory, settings['sample_weight'])
            sample_weight = pandas.read_csv(filename)['sample_weight']
            del settings['sample_weight']
        else:
            sample_weight = None
        model = Earth(**settings)
        model.fit(X, y, sample_weight=sample_weight)
        with open(os.path.join(directory, case + '.txt'), 'r') as infile:
            correct = infile.read()
        assert_equal(model.summary(), correct)
开发者ID:RPGOne,项目名称:han-solo,代码行数:27,代码来源:test_earth.py

示例3: test_copy_compatibility

def test_copy_compatibility():
    model = Earth(**default_params).fit(X, y)
    model_copy = copy.copy(model)
    assert_true(model_copy == model)
    assert_true(
        numpy.all(model.predict(X) == model_copy.predict(X)))
    assert_true(model.basis_[0] is model.basis_[1]._get_root())
    assert_true(model_copy.basis_[0] is model_copy.basis_[1]._get_root())
开发者ID:RPGOne,项目名称:han-solo,代码行数:8,代码来源:test_earth.py

示例4: test_smooth

def test_smooth():
        model = Earth(penalty=1, smooth=True)
        model.fit(X, y)
        res = str(model.trace()) + '\n' + model.summary()
        filename = os.path.join(os.path.dirname(__file__),
                                'earth_regress_smooth.txt')
        with open(filename, 'r') as fl:
            prev = fl.read()
        assert_equal(res, prev)
开发者ID:RPGOne,项目名称:han-solo,代码行数:9,代码来源:test_earth.py

示例5: run_pyearth

def run_pyearth(X, y, **kwargs):
    '''Run with pyearth.  Return prediction value, training time, and number of forward pass iterations.'''
    model = Earth(**kwargs)
    t0 = time.time()
    model.fit(X, y)
    t1 = time.time()
    y_pred = model.predict(X)
    forward_iterations = len(model.forward_trace()) - 1
    return y_pred, t1 - t0, forward_iterations
开发者ID:Biodun,项目名称:py-earth,代码行数:9,代码来源:pyearth_vs_earth.py

示例6: test_fit

def test_fit():
    earth = Earth(**default_params)
    earth.fit(X, y)
    res = str(earth.trace()) + '\n' + earth.summary()
    filename = os.path.join(os.path.dirname(__file__),
                            'earth_regress.txt')
    with open(filename, 'r') as fl:
        prev = fl.read()
    assert_equal(res, prev)
开发者ID:RPGOne,项目名称:han-solo,代码行数:9,代码来源:test_earth.py

示例7: test_pickle_compatibility

def test_pickle_compatibility():
    earth = Earth(**default_params)
    model = earth.fit(X, y)
    model_copy = pickle.loads(pickle.dumps(model))
    assert_true(model_copy == model)
    assert_true(
        numpy.all(model.predict(X) == model_copy.predict(X)))
    assert_true(model.basis_[0] is model.basis_[1]._get_root())
    assert_true(model_copy.basis_[0] is model_copy.basis_[1]._get_root())
开发者ID:RPGOne,项目名称:han-solo,代码行数:9,代码来源:test_earth.py

示例8: test_exhaustive_search

def test_exhaustive_search():
    model = Earth(max_terms=13,
                  enable_pruning=False,
                  check_every=1,
                  thresh=0,
                  minspan=1,
                  endspan=1)
    model.fit(X, y)
    assert_equal(model.basis_.plen(), model.coef_.shape[1])
    assert_equal(model.transform(X).shape[1], len(model.basis_))
开发者ID:RPGOne,项目名称:han-solo,代码行数:10,代码来源:test_earth.py

示例9: test_nb_terms

def test_nb_terms():

    for max_terms in (1, 3, 12, 13):
        model = Earth(max_terms=max_terms)
        model.fit(X, y)
        assert_true(len(model.basis_) <= max_terms)
        assert_true(len(model.coef_) <= len(model.basis_))
        assert_true(len(model.coef_) >= 1)
        if max_terms == 1:
            assert_list_almost_equal_value(model.predict(X), y.mean())
开发者ID:RPGOne,项目名称:han-solo,代码行数:10,代码来源:test_earth.py

示例10: test_feature_importance

def test_feature_importance():
    criteria = ('rss', 'gcv', 'nb_subsets')
    for imp in criteria:
        earth = Earth(feature_importance_type=imp, **default_params)
        earth.fit(X, y)
        assert len(earth.feature_importances_) == X.shape[1]
    earth = Earth(feature_importance_type=criteria, **default_params)
    earth.fit(X, y)
    assert type(earth.feature_importances_) == dict
    assert set(earth.feature_importances_.keys()) == set(criteria)
    for crit, val in earth .feature_importances_.items():
        assert len(val) == X.shape[1]

    assert_raises(
            ValueError,
            Earth(feature_importance_type='bad_name', **default_params).fit,
            X, y)

    earth = Earth(feature_importance_type=('rss',), **default_params)
    earth.fit(X, y)
    assert len(earth.feature_importances_) == X.shape[1]

    assert_raises(
            ValueError,
            Earth(feature_importance_type='rss', enable_pruning=False, **default_params).fit,
            X, y)
开发者ID:mehdidc,项目名称:py-earth,代码行数:26,代码来源:test_earth.py

示例11: test_pandas_compatibility

def test_pandas_compatibility():
    import pandas
    X_df = pandas.DataFrame(X)
    y_df = pandas.DataFrame(y)
    colnames = ['xx' + str(i) for i in range(X.shape[1])]
    X_df.columns = colnames

    earth = Earth(**default_params)
    model = earth.fit(X_df, y_df)
    assert_list_equal(
        colnames, model.forward_trace()._getstate()['xlabels'])
开发者ID:RPGOne,项目名称:han-solo,代码行数:11,代码来源:test_earth.py

示例12: test_smooth

def test_smooth():
    model = Earth(penalty=1, smooth=True)
    model.fit(X, y)
    res = str(model.rsq_)
    filename = os.path.join(os.path.dirname(__file__),
                            'earth_regress_smooth.txt')
#     with open(filename, 'w') as fl:
#         fl.write(res)
    with open(filename, 'r') as fl:
        prev = fl.read()
    assert_true(abs(float(res) - float(prev)) < .05)
开发者ID:mehdidc,项目名称:py-earth,代码行数:11,代码来源:test_earth.py

示例13: test_fit

def test_fit():
    earth = Earth(**default_params)
    earth.fit(X, y)
    res = str(earth.rsq_)
    filename = os.path.join(os.path.dirname(__file__),
                            'earth_regress.txt')
#     with open(filename, 'w') as fl:
#         fl.write(res)
    with open(filename, 'r') as fl:
        prev = fl.read()
    assert_true(abs(float(res) - float(prev)) < .05)
开发者ID:mehdidc,项目名称:py-earth,代码行数:11,代码来源:test_earth.py

示例14: test_linvars

def test_linvars():
    earth = Earth(**default_params)
    earth.fit(X, y, linvars=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    res = str(earth.trace()) + '\n' + earth.summary()
    filename = os.path.join(os.path.dirname(__file__),
                            'earth_linvars_regress.txt')
#     with open(filename, 'w') as fl:
#         fl.write(res)
    with open(filename, 'r') as fl:
        prev = fl.read()

    assert_equal(res, prev)
开发者ID:mehdidc,项目名称:py-earth,代码行数:12,代码来源:test_earth.py

示例15: runModel

def runModel(i,featureCombo):
    mae = np.array([])   
    logging.warning('try alpha = %s' % i)
    for ktrain,ktest in kf:
        x = trainCleaned.iloc[ktrain,]
        y = trainCleaned.iloc[ktest,]    
        model = Earth()
        model.fit(x[featureCombo],x['Expected'])
	pred = model.predict(y[featureCombo])
        mae = np.append(mae,(getMAE(pred,y['Expected'])))
    logging.warning('average 10-fold MAE for alpha %s feature %s' % (i,featureCombo))
    logging.warning(mae.mean())
开发者ID:yunfeiguo,项目名称:kaggle_cs567,代码行数:12,代码来源:testspline.py


注:本文中的pyearth.Earth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。