GridSearchCV
from sklearn.model_selection import GridSearchCV
GridSearchCV(网络搜索交叉验证)用于系统地遍历模型的多种参数组合,通过交叉验证从而确定最佳参数,适用于小数据集。
常用属性
best_score_ :最佳模型下的分数
best_params_ :最佳模型参数
grid_scores_ :模型不同参数下交叉验证的平均分
cv_results_ : 具体用法模型不同参数下交叉验证的结果
best_estimator_ : 最佳分类器之所以出现以上问题
常用函数
score(x_test,y_test):最佳模型在测试集下的分数
问题原因
之所以出现以上问题,原因在于grid_scores_在sklearn0.20版本中已被删除,取而代之的是cv_results_。
模型不同参数下的分数
方法1(0.20版本已删除):
grid_search.grid_scores_
方式2(0.20版本适用的方式):
means = grid_search.cv_results_['mean_test_score']
params = grid_search.cv_results_['params']
因此正确代码为: