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


Python StackingRegressor.predict方法代码示例

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


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

示例1: test_features_in_secondary

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_features_in_secondary():
    lr = LinearRegression()
    svr_lin = SVR(kernel='linear', gamma='auto')
    rf = RandomForestRegressor(n_estimators=10, random_state=2)
    ridge = Ridge(random_state=0)
    svr_rbf = SVR(kernel='rbf', gamma='auto')
    stack = StackingRegressor(regressors=[svr_lin, lr, ridge, rf],
                              meta_regressor=svr_rbf,
                              use_features_in_secondary=True)

    stack.fit(X1, y).predict(X1)
    mse = 0.14
    got = np.mean((stack.predict(X1) - y) ** 2)
    print(got)
    assert round(got, 2) == mse

    stack = StackingRegressor(regressors=[svr_lin, lr, ridge, rf],
                              meta_regressor=svr_rbf,
                              use_features_in_secondary=False)

    # dense
    stack.fit(X1, y).predict(X1)
    mse = 0.12
    got = np.mean((stack.predict(X1) - y) ** 2)
    print(got)
    assert round(got, 2) == mse
开发者ID:rasbt,项目名称:mlxtend,代码行数:28,代码来源:test_stacking_regression.py

示例2: test_multivariate_class

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_multivariate_class():
    lr = LinearRegression()
    ridge = Ridge(random_state=1)
    meta = LinearRegression(normalize=True)
    stregr = StackingRegressor(regressors=[lr, ridge],
                               meta_regressor=meta)
    stregr.fit(X2, y2).predict(X2)
    mse = 0.122
    got = np.mean((stregr.predict(X2) - y2) ** 2)
    assert round(got, 3) == mse
开发者ID:chrinide,项目名称:mlxtend,代码行数:12,代码来源:test_stacking_regression.py

示例3: test_predict_meta_features

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_predict_meta_features():
    lr = LinearRegression()
    svr_rbf = SVR(kernel='rbf')
    ridge = Ridge(random_state=1)
    stregr = StackingRegressor(regressors=[lr, ridge],
                               meta_regressor=svr_rbf)
    X_train, X_test, y_train, y_test = train_test_split(X2, y, test_size=0.3)
    stregr.fit(X_train, y_train)
    test_meta_features = stregr.predict(X_test)
    assert test_meta_features.shape[0] == X_test.shape[0]
开发者ID:NextNight,项目名称:mlxtend,代码行数:12,代码来源:test_stacking_regression.py

示例4: test_multivariate

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_multivariate():
    lr = LinearRegression()
    svr_lin = SVR(kernel='linear')
    ridge = Ridge(random_state=1)
    svr_rbf = SVR(kernel='rbf')
    stregr = StackingRegressor(regressors=[svr_lin, lr, ridge],
                               meta_regressor=svr_rbf)
    stregr.fit(X2, y).predict(X2)
    mse = 0.218
    got = np.mean((stregr.predict(X2) - y) ** 2)
    assert round(got, 3) == mse
开发者ID:chrinide,项目名称:mlxtend,代码行数:13,代码来源:test_stacking_regression.py

示例5: test_different_models

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_different_models():
    lr = LinearRegression()
    svr_lin = SVR(kernel='linear')
    ridge = Ridge(random_state=1)
    svr_rbf = SVR(kernel='rbf')
    stregr = StackingRegressor(regressors=[svr_lin, lr, ridge],
                               meta_regressor=svr_rbf)
    y_pred = stregr.fit(X1, y).predict(X1)
    mse = 0.214
    got = np.mean((stregr.predict(X1) - y) ** 2)
    assert round(got, 3) == mse
开发者ID:datasci-co,项目名称:mlxtend,代码行数:13,代码来源:test_stacking_regression.py

示例6: test_multivariate_class

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_multivariate_class():
    lr = LinearRegression()
    ridge = Ridge(random_state=1)
    meta = LinearRegression(normalize=True)
    stregr = StackingRegressor(regressors=[lr, ridge],
                               meta_regressor=meta)
    stregr.fit(X2, y2).predict(X2)
    mse = 0.12
    got = np.mean((stregr.predict(X2) - y2) ** 2.)
    # there seems to be an issue with the following test on Windows
    # sometimes via Appveyor
    assert round(got, 2) == mse, got
开发者ID:NextNight,项目名称:mlxtend,代码行数:14,代码来源:test_stacking_regression.py

示例7: test_sample_weight

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
def test_sample_weight():
    lr = LinearRegression()
    svr_lin = SVR(kernel='linear', gamma='auto')
    ridge = Ridge(random_state=1)
    svr_rbf = SVR(kernel='rbf', gamma='auto')
    stregr = StackingRegressor(regressors=[svr_lin, lr, ridge],
                               meta_regressor=svr_rbf)
    pred1 = stregr.fit(X1, y, sample_weight=w).predict(X1)
    mse = 0.22
    got = np.mean((stregr.predict(X1) - y) ** 2)
    assert round(got, 2) == mse
    # make sure that this is not equivalent to the model with no weight
    pred2 = stregr.fit(X1, y).predict(X1)
    maxdiff = np.max(np.abs(pred1 - pred2))
    assert maxdiff > 1e-3, "max diff is %.4f" % maxdiff
开发者ID:rasbt,项目名称:mlxtend,代码行数:17,代码来源:test_stacking_regression.py

示例8: train

# 需要导入模块: from mlxtend.regressor import StackingRegressor [as 别名]
# 或者: from mlxtend.regressor.StackingRegressor import predict [as 别名]
  def train(self, X,y):
    features = X
    labels = y

    #test train split
    X_train, X_test, Y_train, Y_test = train_test_split(X, y, test_size=0.25, random_state=4)

    #Ridge
    regcv = linear_model.RidgeCV(alphas=[0.05, 0.1, 0.3, 1, 3, 5, 10, 15, 30, 50, 75])
    regcv.fit(features, labels)
    regcv.alpha_  
    reg = linear_model.Ridge(alpha=regcv.alpha_)
    reg.fit(features, labels)

    # GB
    params = {'n_estimators': 100, 'max_depth': 5, 'min_samples_split': 2,
              'learning_rate': 0.1, 'loss': 'ls'}
    gbr = ensemble.GradientBoostingRegressor(**params)
    gbr.fit(features, labels)


    #blended model
    meta = linear_model.LinearRegression()
    blender = StackingRegressor(regressors=[reg, gbr], meta_regressor=meta)
    _=blender.fit(features, labels)
    y_pred = blender.predict(X_test)

    print "***** TRAINING STATS ********"
    scores = cross_val_score(blender, features, labels, cv=10)
    print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))

    mean_diff = np.mean(np.abs(np.exp(Y_test)-np.exp(y_pred)))
    p_mean_diff = np.mean(mean_diff/np.exp(Y_test))
    print "Mean Error:\t %.0f/%0.3f%%" % (mean_diff, p_mean_diff*100)
    print "***** TRAINING STATS ********"
    
    return blender
开发者ID:eggie5,项目名称:ipython-notebooks,代码行数:39,代码来源:model.py


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