解决这个错误AttributeError: 'GridSearchCV' object has no attribute 'best_params_'
时间: 2023-10-30 18:06:08 浏览: 280
在解决错误"AttributeError: 'GridSearchCV' object has no attribute 'best_params_'"时,可以尝试以下几个步骤:
1. 首先,确保你的scikit-learn库版本高于0.20版本。在0.20版本之前,`grid_scores_`属性被替换为`cv_results_`属性。如果你的版本低于0.20,你需要更新你的scikit-learn库版本。
2. 如果你的版本已经是0.20或更高,那么这个错误可能是因为你没有正确地调用GridSearchCV对象的属性。`best_params_`属性应该是GridSearchCV对象的一个属性,可以通过访问`best_params_`属性来获取最佳参数的值。
3. 确保你已经正确地训练了GridSearchCV对象并执行了网格搜索。在执行网格搜索之后,你才能访问`best_params_`属性来获取最佳参数的值。
综上所述,要解决错误"AttributeError: 'GridSearchCV' object has no attribute 'best_params_'",你可以检查你的scikit-learn库版本,确保你正确地调用了GridSearchCV对象的属性,并且在执行网格搜索之后才访问`best_params_`属性来获取最佳参数的值。
: https://stackoverflow.com/questions/52706696/attributeerror-gridsearchcv-object-has-no-attribute-grid-scores
: https://stackoverflow.com/questions/41102240/attributeerror-gridsearchcv-object-has-no-attribute-grid-scores
: https://scikit-learn.org/0.20/modules/generated/sklearn.model_selection.GridSearchCV.html
阅读全文