获取GridSearchCV的标准差

Nea*_*bfi 3 python scikit-learn cross-validation grid-search data-science

在scikit-learn 0.20之前,我们可以result.grid_scores_[result.best_index_]用来获取标准偏差。(它返回为例:mean: 0.76172, std: 0.05225, params: {'n_neighbors': 21}

scikit学习0.20以获得最佳分数的标准偏差的最佳方法是什么?

Viv*_*mar 5

在较新的版本中,将grid_scores_重命名为cv_results_。根据文档,您需要:

best_index_ : int

The index (of the cv_results_ arrays) which corresponds to the best > 
  candidate parameter setting.

The dict at search.cv_results_['params'][search.best_index_] gives the > 
  parameter setting for the best model, that gives the highest mean
  score (search.best_score_).
Run Code Online (Sandbox Code Playgroud)

因此,您需要

  • 最佳参数:- result.cv_results_['params'][result.best_index_]result.best_params_
  • 最佳平均得分:- result.cv_results_['mean_test_score'][result.best_index_]result.best_score_

  • 最佳标准:- result.cv_results_['std_test_score'][result.best_index_]