我在Gridsearch cv对象中使用管道来调整参数。我的代码如下
X_train = df_train.drop("SalePrice", axis=1)
Y_train = df_train["SalePrice"]
X_test = df_test.drop("Id", axis=1).copy()
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
from sklearn.preprocessing import MinMaxScaler
from sklearn.grid_search import GridSearchCV
from sklearn.decomposition import PCA
from sklearn.pipeline import Pipeline
scaler = MinMaxScaler()
param_grid={'features__pca__n_components':[1, 2, 3,5,10],}
pipeline = Pipeline(steps=[('scaler', scaler),('algorithm',lr)])
gs = GridSearchCV(pipeline, param_grid, scoring='f1')
gs.fit(X_train, Y_train)
print "Best estimator",gs.best_estimator_
clf = gs.best_estimator_
# fit the optimal model
clf.fit(X_train, Y_train)
# predict based on the optimal model
pred = clf.predict(X_test)
acc_log = round(clf.score(X_train, Y_train) * 100, 2)
acc_log
我收到此错误,其中X_train和Y_train参数是numpy数组。
ValueError Traceback (most recent call last)
<ipython-input-681-9e3b37600170> in <module>()
7 pipeline = Pipeline(steps=[('scaler', scaler),('algorithm',lr)])
8 gs = GridSearchCV(pipeline, param_grid, scoring='f1')
----> 9 gs.fit(X_train, Y_train)
10 print "Best estimator",gs.best_estimator_
11 clf = gs.best_estimator_
ValueError: Invalid parameter features for estimator Pipeline(steps=[('scaler', MinMaxScaler(copy=True, feature_range=(0, 1))), ('algorithm', LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False))]). Check the list of available parameters with `estimator.get_params().keys()`.
我应该如何配置参数?
请帮我解决这个问题。谢谢