BaggingClassifier 使用的分类器的调整参数 [英] Tuning parameters of the classifier used by BaggingClassifier

查看:51
本文介绍了BaggingClassifier 使用的分类器的调整参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想训练使用 DecisionTreeClassifierBaggingClassifier:

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 来找到 BaggingClassifierDecisionTreeClassifier 的最佳参数(例如 max_depth来自 DecisionTreeClassifiermax_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 使用的分类器的调整参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆