【发布时间】:2020-08-25 22:37:57
【问题描述】:
我想用 StackingClassifier 组合一些分类器,然后用 GridSearchCV 优化参数:
clf1 = RandomForestClassifier()
clf2 = LogisticRegression()
dt = DecisionTreeClassifier()
sclf = StackingClassifier(estimators=[clf1, clf2],final_estimator=dt)
params = {'randomforestclassifier__n_estimators': [10, 50],
'logisticregression__C': [1,2,3]}
grid = GridSearchCV(estimator=sclf, param_grid=params, cv=5)
grid.fit(x, y)
但这结果是一个错误:
'RandomForestClassifier' object has no attribute 'estimators_'
我用过n_estimators。为什么它警告我没有estimators_?
GridSearchCV 通常应用于单个模型,所以我只需要将单个模型的参数名称写在一个字典中。
我参考了这个页面https://groups.google.com/d/topic/mlxtend/5GhZNwgmtSg,但它使用了早期版本的参数。即使我更改了新参数,它也不起作用。
顺便问一下,这些参数的命名规则在哪里可以了解?
【问题讨论】:
-
如果你执行
sclf.fit(X,y)你会得到什么? -
'RandomForestClassifier' 对象没有属性 'estimators_'
-
看我的回答。希望有帮助
-
请注意,
estimators_拟合在完整的 X 上,而final_estimator_是使用使用cross_val_predictfrom here 的基本估计器的交叉验证预测进行训练的。我猜想在每个折叠中执行基本估计器的网格搜索,然后最好的预测器给出final_estimator_训练的预测,但是......如何执行这个网格搜索?
标签: python scikit-learn gridsearchcv