本文整理汇总了Python中mlxtend.regressor.StackingRegressor类的典型用法代码示例。如果您正苦于以下问题:Python StackingRegressor类的具体用法?Python StackingRegressor怎么用?Python StackingRegressor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StackingRegressor类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_coeff_fail
def test_get_coeff_fail():
lr = LinearRegression()
svr_rbf = SVR(kernel='rbf')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[ridge, lr],
meta_regressor=svr_rbf)
stregr = stregr.fit(X1, y)
got = stregr.coef_
开发者ID:datasci-co,项目名称:mlxtend,代码行数:8,代码来源:test_stacking_regression.py
示例2: test_get_coeff
def test_get_coeff():
lr = LinearRegression()
svr_lin = SVR(kernel='linear')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[svr_lin, lr],
meta_regressor=ridge)
stregr.fit(X1, y)
got = stregr.coef_
expect = np.array([0.4874216, 0.45518317])
assert_almost_equal(got, expect)
开发者ID:chrinide,项目名称:mlxtend,代码行数:10,代码来源:test_stacking_regression.py
示例3: test_predict_meta_features
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,代码行数:10,代码来源:test_stacking_regression.py
示例4: test_get_intercept
def test_get_intercept():
lr = LinearRegression()
svr_lin = SVR(kernel='linear')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[svr_lin, lr],
meta_regressor=ridge)
stregr.fit(X1, y)
got = stregr.intercept_
expect = 0.024
assert round(got, 3) == expect
开发者ID:chrinide,项目名称:mlxtend,代码行数:10,代码来源:test_stacking_regression.py
示例5: test_multivariate_class
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,代码行数:10,代码来源:test_stacking_regression.py
示例6: test_different_models
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,代码行数:11,代码来源:test_stacking_regression.py
示例7: test_train_meta_features_
def test_train_meta_features_():
lr = LinearRegression()
svr_rbf = SVR(kernel='rbf')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[lr, ridge],
meta_regressor=svr_rbf,
store_train_meta_features=True)
X_train, X_test, y_train, y_test = train_test_split(X2, y, test_size=0.3)
stregr.fit(X_train, y_train)
train_meta_features = stregr.train_meta_features_
assert train_meta_features.shape[0] == X_train.shape[0]
开发者ID:NextNight,项目名称:mlxtend,代码行数:11,代码来源:test_stacking_regression.py
示例8: test_get_coeff_fail
def test_get_coeff_fail():
lr = LinearRegression()
svr_rbf = SVR(kernel='rbf', gamma='auto')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[ridge, lr],
meta_regressor=svr_rbf)
with pytest.raises(AttributeError):
stregr = stregr.fit(X1, y)
r = stregr.coef_
assert r
开发者ID:rasbt,项目名称:mlxtend,代码行数:11,代码来源:test_stacking_regression.py
示例9: test_multivariate
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,代码行数:11,代码来源:test_stacking_regression.py
示例10: test_multivariate_class
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,代码行数:12,代码来源:test_stacking_regression.py
示例11: test_weight_ones
def test_weight_ones():
# sample weight of ones should produce equivalent outcome as no 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).predict(X1)
pred2 = stregr.fit(X1, y, sample_weight=np.ones(40)).predict(X1)
maxdiff = np.max(np.abs(pred1 - pred2))
assert maxdiff < 1e-3, "max diff is %.4f" % maxdiff
开发者ID:rasbt,项目名称:mlxtend,代码行数:12,代码来源:test_stacking_regression.py
示例12: test_weight_unsupported_meta
def test_weight_unsupported_meta():
# meta regressor with no support for
# sample_weight should raise error
lr = LinearRegression()
svr_lin = SVR(kernel='linear', gamma='auto')
ridge = Ridge(random_state=1)
lasso = Lasso(random_state=1)
stregr = StackingRegressor(regressors=[svr_lin, lr, ridge],
meta_regressor=lasso)
with pytest.raises(TypeError):
stregr.fit(X1, y, sample_weight=w).predict(X1)
开发者ID:rasbt,项目名称:mlxtend,代码行数:12,代码来源:test_stacking_regression.py
示例13: test_weight_unsupported_regressor
def test_weight_unsupported_regressor():
# including regressor that does not support
# sample_weight should raise error
lr = LinearRegression()
svr_lin = SVR(kernel='linear', gamma='auto')
ridge = Ridge(random_state=1)
svr_rbf = SVR(kernel='rbf', gamma='auto')
lasso = Lasso(random_state=1)
stregr = StackingRegressor(regressors=[svr_lin, lr, ridge, lasso],
meta_regressor=svr_rbf)
with pytest.raises(TypeError):
stregr.fit(X1, y, sample_weight=w).predict(X1)
开发者ID:rasbt,项目名称:mlxtend,代码行数:13,代码来源:test_stacking_regression.py
示例14: test_features_in_secondary
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,代码行数:26,代码来源:test_stacking_regression.py
示例15: test_sample_weight
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,代码行数:15,代码来源:test_stacking_regression.py
示例16: test_get_params
def test_get_params():
lr = LinearRegression()
svr_rbf = SVR(kernel='rbf')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[ridge, lr],
meta_regressor=svr_rbf)
got = sorted(list({s.split('__')[0] for s in stregr.get_params().keys()}))
expect = ['linearregression',
'meta-svr',
'meta_regressor',
'regressors',
'ridge',
'store_train_meta_features',
'verbose']
assert got == expect, got
开发者ID:venkatesh-1729,项目名称:mlxtend,代码行数:16,代码来源:test_stacking_regression.py
示例17: test_predictions_from_sparse_matrix
def test_predictions_from_sparse_matrix():
lr = LinearRegression()
svr_lin = SVR(kernel='linear', gamma='auto')
ridge = Ridge(random_state=1)
stregr = StackingRegressor(regressors=[svr_lin, lr],
meta_regressor=ridge)
# dense
stregr.fit(X1, y)
print(stregr.score(X1, y))
assert round(stregr.score(X1, y), 2) == 0.61
# sparse
stregr.fit(sparse.csr_matrix(X1), y)
print(stregr.score(X1, y))
assert round(stregr.score(X1, y), 2) == 0.61
开发者ID:rasbt,项目名称:mlxtend,代码行数:16,代码来源:test_stacking_regression.py
示例18: train
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,代码行数:37,代码来源:model.py
示例19: test_weight_unsupported_with_no_weight
def test_weight_unsupported_with_no_weight():
# pass no weight to regressors with no weight support
# should not be a problem
lr = LinearRegression()
svr_lin = SVR(kernel='linear', gamma='auto')
ridge = Ridge(random_state=1)
svr_rbf = SVR(kernel='rbf', gamma='auto')
lasso = Lasso(random_state=1)
stregr = StackingRegressor(regressors=[svr_lin, lr, ridge, lasso],
meta_regressor=svr_rbf)
stregr.fit(X1, y).predict(X1)
stregr = StackingRegressor(regressors=[svr_lin, lr, ridge],
meta_regressor=lasso)
stregr.fit(X1, y).predict(X1)
开发者ID:rasbt,项目名称:mlxtend,代码行数:15,代码来源:test_stacking_regression.py
注:本文中的mlxtend.regressor.StackingRegressor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论