Parameters 理解sklearn网格搜索
我正在努力理解Parameters 理解sklearn网格搜索,parameters,scikit-learn,grid-search,Parameters,Scikit Learn,Grid Search,我正在努力理解grid\u search类是如何工作的。我想找到最佳的max_depth参数,该参数可与RandomForestClassifier一起使用。我指定了希望搜索运行的可能选项,并希望模块输出“最佳拟合”max_depth选项 from sklearn.datasets import load_iris from sklearn.ensemble import RandomForestClassifier from sklearn import grid_search iris=
grid\u search
类是如何工作的。我想找到最佳的max_depth
参数,该参数可与RandomForestClassifier
一起使用。我指定了希望搜索运行的可能选项,并希望模块输出“最佳拟合”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'])
我希望我的explorer
网格搜索模块返回最佳max_depth
参数,给定一组可能的选项[1,2,3,4]
。为什么仍在使用None
的默认值?如何使用grid\u 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)
这些只是调用网格搜索时使用的参数。要确定最佳参数,请使用
资源管理器。最佳参数
,或者您可以使用资源管理器找到估计器。如果启用了重新安装
,则最佳估计器
。如何访问这些值<代码>估计值和最佳参数不是。在我的示例中,当我检查explorer.best_params
和explorer.best_estimator
时,会出现属性错误。它们列在链接页面的属性部分。它们应该在调用fit
后出现。