我想使用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)
,你会得到什么? - seraloukestimators_
是在完整的 X 上拟合的,而final_estimator_
则是使用基本估计器的交叉验证预测进行训练的,使用了cross_val_predict
来自此处。我猜想基本估计器的网格搜索是在每个折叠中执行的,然后最佳预测器为final_estimator_
的训练提供预测,但是...这个final_estimator_
的网格搜索是如何执行的呢? - makpalan