• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyearth.Earth类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_untrained

def test_untrained():

    model = Earth(**default_params)
    assert_raises(NotFittedError, model.predict, X)
    assert_raises(NotFittedError, model.transform, X)
    assert_raises(NotFittedError, model.predict_deriv, X)
    assert_raises(NotFittedError, model.score, X)

    # the following should be changed to raise NotFittedError
    assert_equal(model.forward_trace(), None)
    assert_equal(model.pruning_trace(), None)
    assert_equal(model.summary(), "Untrained Earth Model")
开发者ID:Biodun,项目名称:py-earth,代码行数:12,代码来源:test_earth.py


示例17: test_nb_degrees

def test_nb_degrees():
    for max_degree in (1, 2, 12, 13):
        model = Earth(max_terms=10,
                      max_degree=max_degree,
                      enable_pruning=False,
                      check_every=1,
                      thresh=0,
                      minspan=1,
                      endspan=1)
        model.fit(X, y)
        for basis in model.basis_:
            assert_true(basis.degree() >= 0)
            assert_true(basis.degree() <= max_degree)
开发者ID:RPGOne,项目名称:han-solo,代码行数:13,代码来源:test_earth.py


示例18: test_missing_data

def test_missing_data():
    earth = Earth(allow_missing=True, **default_params)
    missing_ = numpy.random.binomial(1, .05, X.shape).astype(bool)
    X_ = X.copy()
    X_[missing_] = None
    earth.fit(X_, y)
    res = str(earth.score(X_, y))
    filename = os.path.join(os.path.dirname(__file__),
                            'earth_regress_missing_data.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)) < .03)
开发者ID:RPGOne,项目名称:han-solo,代码行数:14,代码来源:test_earth.py


示例19: test_eq

def test_eq():
    model1 = Earth(**default_params)
    model2 = Earth(**default_params)
    assert_equal(model1, model2)
    assert_not_equal(model1, 5)

    params = {}
    params.update(default_params)
    params["penalty"] = 15
    model2 = Earth(**params)
    assert_not_equal(model1, model2)

    model3 = Earth(**default_params)
    model3.unknown_parameter = 5
    assert_not_equal(model1, model3)
开发者ID:RPGOne,项目名称:han-solo,代码行数:15,代码来源:test_earth.py


示例20: test_output_weight

def test_output_weight():
    x = numpy.random.uniform(-1, 1, size=(1000, 1))
    y = (numpy.dot(x, numpy.random.normal(0, 1, size=(1, 10)))) ** 5 + 1
    y = (y - y.mean(axis=0)) / y.std(axis=0)
    group = numpy.array([1] * 5 + [0] * 5)
    output_weight = numpy.array([1] * 5 + [2] * 5, dtype=float)
    model = Earth().fit(x, y, output_weight=output_weight)

    # Check that the model fits at least better
    # the more heavily weighted group
    mse = ((model.predict(x) - y)**2).mean(axis=0)
    group1_mean = mse[group].mean()
    group2_mean = mse[numpy.logical_not(group)].mean()
    assert_true(group1_mean > group2_mean or
                round(abs(group1_mean - group2_mean), 7) == 0)
开发者ID:RPGOne,项目名称:han-solo,代码行数:15,代码来源:test_earth.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyebset.BitSet类代码示例发布时间:2022-05-25
下一篇:
Python pyeapi.load_config函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap