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


Python Earth.fit方法代码示例

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


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

示例1: test_pathological_cases

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:29,代码来源:test_earth.py

示例2: test_fit

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:11,代码来源:test_earth.py

示例3: run_pyearth

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:11,代码来源:pyearth_vs_earth.py

示例4: test_smooth

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:11,代码来源:test_earth.py

示例5: test_exhaustive_search

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:12,代码来源:test_earth.py

示例6: test_nb_terms

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:12,代码来源:test_earth.py

示例7: test_xlabels

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
def test_xlabels():

    model = Earth(**default_params)
    assert_raises(ValueError, model.fit, X[:, 0:5], y, xlabels=['var1', 'var2'])

    model = Earth(**default_params)
    model.fit(X[:, 0:3], y, xlabels=['var1', 'var2', 'var3'])

    model = Earth(**default_params)
    model.fit(X[:, 0:3], y, xlabels=['var1', 'var2', 'var3'])
开发者ID:RPGOne,项目名称:han-solo,代码行数:12,代码来源:test_earth.py

示例8: test_smooth

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:13,代码来源:test_earth.py

示例9: test_fit

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:13,代码来源:test_earth.py

示例10: test_linvars

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:14,代码来源:test_earth.py

示例11: runModel

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:14,代码来源:testspline.py

示例12: test_nb_degrees

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:15,代码来源:test_earth.py

示例13: test_missing_data

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
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,代码行数:16,代码来源:test_earth.py

示例14: marsmodelorr

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
 def marsmodelorr(self, use_smY=True, slope_trunc=0.00001, savgol_window=151, savgol_order=3, ex_order=51):
     Xf, Yf = self.Xf_, self.Yf_
     X, Y = self.X_, self.Y_
     fom = {}
     # smooth the data
     smY = savgol(Y, savgol_window, savgol_order)
     # perform mars
     model = MARS()
     if use_smY:
         model.fit(X, smY)
     else:
         model.fit(X, Y)
     Y_h = model.predict(X)
     '''
     calculate dydx based on mars model to get knots and intercepts as this is 
     complicated to extract from hinge functions
     '''
     diff1 = np.diff(Y_h) / np.diff(X)
     tdiff1 = diff1 - np.nanmin(diff1)
     tdiff1 = tdiff1 / np.nanmax(tdiff1)
     #calculate slopes of linear segments
     ID = [i for i in range(1, len(tdiff1)) if np.abs(tdiff1[i] - tdiff1[i - 1]) > slope_trunc]
     ID.insert(0, 0)
     ID.append(np.argmax(X))  # this might cause an error
     slopes = [np.nanmean(diff1[ID[i - 1]:ID[i]]) for i in range(1, len(ID) - 1)]
     a = [Y_h[ID[i]] - slopes[i] * X[ID[i]] for i in range(len(ID) - 2)]
     IDM, IDm = np.argmax(slopes), np.argmin(np.abs(slopes))
     # intercept of highest slope and zero as well as highest slope and lowest slope
     fom['zinter'] = -a[IDM] / slopes[IDM]
     fom['lminter'] = (a[IDM] - a[IDm]) / (slopes[IDm] - slopes[IDM])
     fom['max_slope'] = slopes[IDM]
     fom['curr_lminter_model'] = fom['lminter'] * slopes[IDM] + a[IDM]
     fom['curr_lminter_data'] = np.mean(Y[np.where(np.abs(X - fom['lminter']) < 0.5)[0]])
     # calculate how the CV curves kight look like without the 'ORR part'
     srYs = smY - model.predict(X)
     srYf = savgol(Yf - model.predict(Xf), savgol_window, savgol_order)
     # calculate their derivative
     dsrYf = savgol(np.diff(srYf) / np.diff(Xf), savgol_window, savgol_order)
     # find the extrema in the derivatives for extraction of redox pots
     redID_f = argrelextrema(srYf, np.less, order=ex_order)
     oxID_f = argrelextrema(srYf, np.greater, order=ex_order)
     # calc some more foms like position of redox waves
     fom['redpot_f'], fom['redpot_f_var'] = np.nanmean(Xf[redID_f]), np.nanstd(Xf[redID_f])
     fom['oxpot_f'], fom['oxpot_f_var'] = np.nanmean(Xf[oxID_f]), np.nanstd(Xf[oxID_f])
     fom['X'], fom['Xf'] = X, Xf
     fom['srYs'], fom['srYf'], fom['smY'] = srYs, srYf, smY
     fom['Y'], fom['Yf'], fom['Y_h'] = Y, Yf, Y_h
     fom['noise_lvl'] = np.sum((Y_h - Y) ** 2, axis=0)
     self.fom = fom
开发者ID:johnmgregoire,项目名称:JCAPDataProcess,代码行数:51,代码来源:CV_ORR.py

示例15: test_fast

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import fit [as 别名]
def test_fast():
    earth = Earth(max_terms=10,
                  max_degree=5,
                  **default_params)
    earth.fit(X, y)
    normal_summary = earth.summary()
    earth = Earth(use_fast=True,
                  max_terms=10,
                  max_degree=5,
                  fast_K=10,
                  fast_h=1,
                  **default_params)
    earth.fit(X, y)
    fast_summary = earth.summary()
    assert_equal(normal_summary, fast_summary)
开发者ID:RPGOne,项目名称:han-solo,代码行数:17,代码来源:test_earth.py


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