首页 > 解决方案 > 我不清楚 GridSearchCV 中 best_score_ 的含义

问题描述

我对几个模型进行了实验,并为每个模型生成了一个最佳分数,以帮助我决定为最终模型选择一个。使用以下代码生成了最好的分数结果:

print(f'Ridge score is {np.sqrt(ridge_grid_search.best_score_ * -1)}')
print(f'Lasso score is {np.sqrt(lasso_grid_search.best_score_ * -1)}')
print(f'ElasticNet score is {np.sqrt(ElasticNet_grid_search.best_score_ * -1)}')
print(f'KRR score is {np.sqrt(KRR_grid_search.best_score_ * -1)}')
print(f'GradientBoosting score is {np.sqrt(gradientBoost_grid_search.best_score_ * -1)}')
print(f'XGBoosting score is {np.sqrt(XGB_grid_search.best_score_ * -1)}')
print(f'LGBoosting score is {np.sqrt(LGB_grid_search.best_score_ * -1)}')

结果发布在这里:

Ridge score is 0.11353489315048314
Lasso score is 0.11118171778462431
ElasticNet score is 0.11122236468840378
KRR score is 0.11322596291030147
GradientBoosting score is 0.11111049287476948
XGBoosting score is 0.11404604560959673
LGBoosting score is 0.11299104859531962

我不知道如何选择最好的模型。在这种情况下,XGBoosting 是我最好的模型吗?

标签: pythonpipelinegridsearchcv

解决方案


但是,您的代码未从ridge_grid_search我想您sklearn.model_selection.GridSearchCV用于模型选择的名称中提供。GridSearch 应该用来调整单个模型的超参数,而不应该用来比较不同的模型。ridge_grid_search.best_score_返回在给定算法的网格搜索期间找到的最佳超参数所获得的最佳分数。

对于模型比较,您应该使用交叉验证算法,例如k 折交叉验证在使用交叉验证时,请确保每个模型都在相同的训练/测试集上进行训练和测试,以便进行公平比较。


推荐阅读