问题描述
说我想训练使用 DecisionTreeClassifier
的 BaggingClassifier
:
Say that I want to train BaggingClassifier
that uses DecisionTreeClassifier
:
dt = DecisionTreeClassifier(max_depth = 1)
bc = BaggingClassifier(dt, n_estimators = 500, max_samples = 0.5, max_features = 0.5)
bc = bc.fit(X_train, y_train)
我想使用 GridSearchCV
来找到 BaggingClassifier
和 DecisionTreeClassifier
的最佳参数(例如 max_depth
来自 DecisionTreeClassifier
和 max_samples
来自 BaggingClassifier
),它的语法是什么?
I would like to use GridSearchCV
to find the best parameters for both BaggingClassifier
and DecisionTreeClassifier
(e.g. max_depth
from DecisionTreeClassifier
and max_samples
from BaggingClassifier
), what is the syntax for this?
推荐答案
我自己找到了解决方案:
I found the solution myself:
param_grid = {
'base_estimator__max_depth' : [1, 2, 3, 4, 5],
'max_samples' : [0.05, 0.1, 0.2, 0.5]
}
clf = GridSearchCV(BaggingClassifier(DecisionTreeClassifier(),
n_estimators = 100, max_features = 0.5),
param_grid, scoring = choosen_scoring)
clf.fit(X_train, y_train)
即说 max_depth
属于" __
base_estimator
,即我的 DecisionTreeClassifier
在这种情况下.这有效并返回正确的结果.
i.e. saying that max_depth
"belongs to" __
the base_estimator
, i.e. my DecisionTreeClassifier
in this case. This works and returns the correct results.
这篇关于BaggingClassifier 使用的分类器的调整参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!