Gridsearch在管道中

时间:2016-05-04 07:37:20

标签: python scikit-learn pipeline grid-search

我在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中的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

简单 - 你错了parameter name

  

class_weight :dict,dicts列表,“balanced”,“balanced_subsample”或None,可选

相关问题