sklearn 中的网格搜索交叉验证

2023-12-24

网格搜索交叉验证可以用于通过决策树分类器提取最佳参数吗?http://scikit-learn.org/stable/tutorial/statistical_inference/model_selection.html http://scikit-learn.org/stable/tutorial/statistical_inference/model_selection.html


为什么不 ?

我邀请您查看以下文档网格搜索简历 http://scikit-learn.org/stable/modules/generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search.GridSearchCV.

Example

from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import roc_auc_score

param_grid = {'max_depth': np.arange(3, 10)}

tree = GridSearchCV(DecisionTreeClassifier(), param_grid)

tree.fit(xtrain, ytrain)
tree_preds = tree.predict_proba(xtest)[:, 1]
tree_performance = roc_auc_score(ytest, tree_preds)

print 'DecisionTree: Area under the ROC curve = {}'.format(tree_performance)

并提取最佳参数:

tree.best_params_
Out[1]: {'max_depth': 5}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

sklearn 中的网格搜索交叉验证 的相关文章

随机推荐