通过投票分类器运行GridSearch

时间:2019-05-29 21:29:25

标签: python machine-learning scikit-learn

尝试在结合了几个分类器的投票集合上运行gridsearch。运行代码时,我总是遇到相同的错误

ValueError: Invalid parameter n_estimator for estimator GradientBoostingClassifier(criterion='friedman_mse', init=None,
              learning_rate=0.1, loss='deviance', max_depth=3,
              max_features=None, max_leaf_nodes=None,
              min_impurity_decrease=0.0, min_impurity_split=None,
              min_samples_leaf=1, min_samples_split=2,
              min_weight_fraction_leaf=0.0, n_estimators=100,
              n_iter_no_change=None, presort='auto', random_state=1,
              subsample=1.0, tol=0.0001, validation_fraction=0.1,
              verbose=0, warm_start=False). Check the list of available parameters with `estimator.get_params().keys()`.

这是我的代码:

dtc = DecisionTreeClassifier(random_state=1)
rfc = RandomForestClassifier(random_state=1)
ada = AdaBoostClassifier(random_state=1)
gdb = GradientBoostingClassifier(random_state=1)
eclf = VotingClassifier(estimators=[('dtc',dtc),('rfc',rfc),
                                          ('ada',ada),('gdb',gdb)],voting='hard')
#tuning parameters with gridsearch
params = [{'gdb__n_estimator':[10,20]}]
grid_search = GridSearchCV(eclf,params,cv=5,scoring='accuracy')
grid_search.fit(X_train,y_train)

1 个答案:

答案 0 :(得分:2)

更仔细地观察,您会发现参数的实际名称为n_estimators(复数);因此,您的params应该是:

params = [{'gdb__n_estimators':[10,20]}]

即这只是一个错字。

相关问题