【发布时间】:2019-06-29 19:33:49
【问题描述】:
这是对 a question answered here 的跟进,但我相信它值得拥有自己的主题。
在上一个问题中,我们处理的是“Ensemble of Ensemble 分类器,其中每个分类器都有自己的参数”。让我们从MaximeKan在他的回答中提供的例子开始:
my_est = BaggingClassifier(RandomForestClassifier(n_estimators = 100, bootstrap = True,
max_features = 0.5), n_estimators = 5, bootstrap_features = False, bootstrap = False,
max_features = 1.0, max_samples = 0.6 )
现在说我想再上一层:抛开效率、计算成本等考虑因素,作为一个一般概念:我将如何使用这种设置运行网格搜索?
我可以按照这些思路设置两个参数网格:
BaggingClassifier:
BC_param_grid = {
'bootstrap': [True, False],
'bootstrap_features': [True, False],
'n_estimators': [5, 10, 15],
'max_samples' : [0.6, 0.8, 1.0]
}
还有一个RandomForestClassifier:
RFC_param_grid = {
'bootstrap': [True, False],
'n_estimators': [100, 200, 300],
'max_features' : [0.6, 0.8, 1.0]
}
现在我可以用我的估算器调用网格搜索:
grid_search = GridSearchCV(estimator = my_est, param_grid = ???)
在这种情况下我该如何处理param_grid 参数?或者更具体地说,如何使用我设置的两个参数网格?
不得不说,感觉就像在玩matryoshka dolls。
【问题讨论】:
-
我建议尝试这里推荐的方法:stackoverflow.com/questions/47570307/…。显然,把
base_estimator__<param name> = [...],即。base_estimator__max_depth = [...]在您的param_grid中足以告诉 GridSearchCV 该特定参数列表用于您的基本估计器的超参数之一(在您的情况下为 RandomForestClassifier)。 -
@James Dellinger - 谢谢,成功了!我听从了你的建议并从那里扩展。为了我们的子孙后代,我将发布最终版本作为答案...
标签: scikit-learn random-forest grid-search ensemble-learning