管道中的网格搜索
Gridsearch in pipeline
我正在使用 Scikit 中的 GridSearchCV
在管道中搜索参数。
我使我的代码工作,但如果我想添加 class_weights
,我就碰壁了。
from sklearn.pipeline import Pipeline
RFC = RandomForestClassifier()
PCA = PCA()
pipe = Pipeline(steps=[('PCA', PCA), ('RFC', RFC)])
param_dict = {'RFC__n_estimators': [100,150],
'RFC__class_weights': [{0:1,1:2},{0:1,1:4}],
'PCA__n_components': [60,80]}
from sklearn.grid_search import GridSearchCV
estimator = GridSearchCV(pipe, param_dict, scoring='roc_auc')
estimator.fit(X_train, y_train)
将此参数添加到 GridSearch 的正确方法是什么?
很简单 - 你搞错了 parameter name:
class_weight : dict, list of dicts, “balanced”, “balanced_subsample” or None, optional
我正在使用 Scikit 中的 GridSearchCV
在管道中搜索参数。
我使我的代码工作,但如果我想添加 class_weights
,我就碰壁了。
from sklearn.pipeline import Pipeline
RFC = RandomForestClassifier()
PCA = PCA()
pipe = Pipeline(steps=[('PCA', PCA), ('RFC', RFC)])
param_dict = {'RFC__n_estimators': [100,150],
'RFC__class_weights': [{0:1,1:2},{0:1,1:4}],
'PCA__n_components': [60,80]}
from sklearn.grid_search import GridSearchCV
estimator = GridSearchCV(pipe, param_dict, scoring='roc_auc')
estimator.fit(X_train, y_train)
将此参数添加到 GridSearch 的正确方法是什么?
很简单 - 你搞错了 parameter name:
class_weight : dict, list of dicts, “balanced”, “balanced_subsample” or None, optional