具有 RF、PCA 和 CV 生成错误的管道
Pipeline with RF, PCA and CV generating error
我正在拟合一个随机森林回归模型,使用流水线 PCA 和网格搜索来选择超参数,但它以某种方式给了我一个错误。下面是我的代码:
params_rf = {'RandomForestRegressor__n_estimators': [300, 400, 500],
'RandomForestRegressor__max_depth': [4, 6, 8],
'RandomForestRegressor__min_samples_leaf': [0.1, 0.2],
'RandomForestRegressor__max_features': ['log2', 'sqrt']}
pipe = Pipeline([('scaler', StandardScaler()),
('reducer', PCA(n_components=50)),
('regressor',RandomForestRegressor(verbose = 3))])
rf_cv = GridSearchCV(estimator = pipe,
param_grid = params_rf,
cv =3,
verbose=3)
rf_cv.fit(X_train,y_train)
错误信息:
Invalid parameter RandomForestRegressor_max_depth for estimator Pipeline(steps=[('scaler', StandardScaler()), ('reducer', PCA(n_components=50)),
('regressor', RandomForestRegressor(verbose=3))]). Check the list of available parameters with `estimator.get_params().keys()`.
我试过去掉'RandomForestRegressor_'前缀,问题依旧。我很漂亮 max_depth
实际上是 RandomForestRegressor
中的一个超参数
RandomForestRegressor
,在您的管道中使用,已经有一个名称,regressor
;你应该用这个名字来引用它,而不是 RandomForestRegressor
。将您的 params_rf
更改为:
params_rf = {'regressor__n_estimators': [300, 400, 500],
'regressor__max_depth': [4, 6, 8],
'regressor__min_samples_leaf': [0.1, 0.2],
'regressor__max_features': ['log2', 'sqrt']}
我正在拟合一个随机森林回归模型,使用流水线 PCA 和网格搜索来选择超参数,但它以某种方式给了我一个错误。下面是我的代码:
params_rf = {'RandomForestRegressor__n_estimators': [300, 400, 500],
'RandomForestRegressor__max_depth': [4, 6, 8],
'RandomForestRegressor__min_samples_leaf': [0.1, 0.2],
'RandomForestRegressor__max_features': ['log2', 'sqrt']}
pipe = Pipeline([('scaler', StandardScaler()),
('reducer', PCA(n_components=50)),
('regressor',RandomForestRegressor(verbose = 3))])
rf_cv = GridSearchCV(estimator = pipe,
param_grid = params_rf,
cv =3,
verbose=3)
rf_cv.fit(X_train,y_train)
错误信息:
Invalid parameter RandomForestRegressor_max_depth for estimator Pipeline(steps=[('scaler', StandardScaler()), ('reducer', PCA(n_components=50)),
('regressor', RandomForestRegressor(verbose=3))]). Check the list of available parameters with `estimator.get_params().keys()`.
我试过去掉'RandomForestRegressor_'前缀,问题依旧。我很漂亮 max_depth
实际上是 RandomForestRegressor
RandomForestRegressor
,在您的管道中使用,已经有一个名称,regressor
;你应该用这个名字来引用它,而不是 RandomForestRegressor
。将您的 params_rf
更改为:
params_rf = {'regressor__n_estimators': [300, 400, 500],
'regressor__max_depth': [4, 6, 8],
'regressor__min_samples_leaf': [0.1, 0.2],
'regressor__max_features': ['log2', 'sqrt']}