【发布时间】:2016-03-31 06:21:27
【问题描述】:
我很难理解grid_search 类的工作原理。我想找到可以与RandomForestClassifier 一起使用的最佳max_depth 参数。我指定了我希望搜索运行的可能选项,并且我希望模块输出“最合适的”max_depth 选项。
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn import grid_search
iris= load_iris()
forest_parameters = {'max_depth': [1,2,3,4]}
forest = RandomForestClassifier()
explorer = grid_search.GridSearchCV(forest, forest_parameters)
explorer.fit(iris['data'], iris['target'])
给定一组可能的选项[1,2,3,4],我希望我的explorer 网格搜索模块返回最佳max_depth 参数。为什么None的默认值还在使用?如何使用grid_search 找到“最佳拟合”参数?
Out[13]:
GridSearchCV(cv=None, error_score='raise',
estimator=RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
---> max_depth=None, max_features='auto', max_leaf_nodes=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
oob_score=False, random_state=None, verbose=0,
warm_start=False),
fit_params={}, iid=True, loss_func=None, n_jobs=1,
param_grid={'max_depth': [1, 2, 3, 4]}, pre_dispatch='2*n_jobs',
refit=True, score_func=None, scoring=None, verbose=0)
【问题讨论】:
标签: parameters scikit-learn grid-search