小编ste*_*anE的帖子

sklearn管道 - 在管道中应用多项式特征变换后应用样本权重

我想应用样本权重,同时使用来自sklearn的管道(应该进行特征转换,例如多项式),然后应用回归量,例如ExtraTrees.

我在以下两个示例中使用以下包:

from sklearn.ensemble import ExtraTreesRegressor
import numpy as np
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures
Run Code Online (Sandbox Code Playgroud)

只要我单独转换功能并在之后生成和训练模型,一切都很顺利:

#Feature generation
X = np.random.rand(200,4)
Y = np.random.rand(200)

#Feature transformation
poly = PolynomialFeatures(degree=2)
poly.fit_transform(X)

#Model generation and fit
clf = ExtraTreesRegressor(n_estimators=5, max_depth = 3)
weights = [1]*100 + [2]*100
clf.fit(X,Y, weights)
Run Code Online (Sandbox Code Playgroud)

但是在管道中执行它不起作用:

#Pipeline generation
pipe = Pipeline([('poly2', PolynomialFeatures(degree=2)), ('ExtraTrees', ExtraTreesRegressor(n_estimators=5, max_depth = 3))])

#Feature generation
X = np.random.rand(200,4)
Y = np.random.rand(200)

#Fitting model
clf = pipe
weights = [1]*100 + [2]*100 …
Run Code Online (Sandbox Code Playgroud)

python pipeline python-2.7 scikit-learn

9
推荐指数
1
解决办法
2857
查看次数

标签 统计

pipeline ×1

python ×1

python-2.7 ×1

scikit-learn ×1