这里有一个有趣的问题 - 我有GridSearchCV
结果,在从属性中挑选之后,grid_search_cv.results_
捕获如下:
Input: pd.DataFrame(grid_clf_rf.cv_results_).iloc[4966]['params']
Output: {'rf__max_depth': 40, 'rf__max_features': 2, 'rf__n_estimators': 310}
现在,据我了解,Imbalanced Learn 包的 Pipeline 对象是 SciKit-Learn 的 Pipeline 的包装器,它应该**fit_params
在其方法中接受参数.fit()
,如下所示:
clf = BalancedRandomForestClassifier(random_state = random_state,
n_jobs = n_jobs)
pipeline = Pipeline([('nt', nt), ('rf', clf)])
pipeline.fit(X_train, y_train, **pd.DataFrame(grid_clf_rf.cv_results_).iloc[4966]['params'])
但是,当我执行上述表达式时,我得到以下结果:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-64-a26424dc8038> in <module>
4 pipeline = Pipeline([('nt', nt), ('rf', clf)])
5
----> 6 pipeline.fit(X_train, y_train, **pd.DataFrame(grid_clf_rf.cv_results_).iloc[4966]['params'])
7
8 print_scores(pipeline, X_train, y_train, X_test, y_test)
/opt/conda/lib/python3.7/site-packages/imblearn/pipeline.py in fit(self, X, y, **fit_params)
237 Xt, yt, fit_params = self._fit(X, y, **fit_params)
238 if self._final_estimator is not None:
--> 239 self._final_estimator.fit(Xt, yt, **fit_params)
240 return self
241
TypeError: fit() got an unexpected keyword argument 'max_features'
任何想法我做错了什么?