在 Gridsearch CV 中评分

KMi*_*tal 8 python machine-learning grid-search data-science

我刚开始使用 Python 中的 GridSearchCV,但我很困惑这其中的得分是什么。我见过的地方

scorers = {
    'precision_score': make_scorer(precision_score),
    'recall_score': make_scorer(recall_score),
    'accuracy_score': make_scorer(accuracy_score)
}

grid_search = GridSearchCV(clf, param_grid, scoring=scorers, refit=refit_score,
                       cv=skf, return_train_score=True, n_jobs=-1)
Run Code Online (Sandbox Code Playgroud)

使用这些值的目的是什么,即准确率、召回率、评分准确率?

这是否被 gridsearch 用于根据这些评分值为我们提供优化的参数....例如对于最佳精度分数,它会找到最佳参数或类似的东西?

它计算可能参数的准确率、召回率、准确率并给出结果,现在的问题是,如果这是真的,那么它会根据准确率、召回率或准确率选择最佳参数吗?上面的说法是真的吗?

G. *_*son 12

你的假设基本上是正确的。此参数字典允许网格搜索优化每个评分指标并为每个评分找到最佳参数。

但是,您不能让 gridsearch 自动适应并返回best_estimator_,而不选择用于 的分数refit,而是会抛出以下错误:

ValueError: For multi-metric scoring, the parameter refit must be set to a scorer 
key to refit an estimator with the best parameter setting on the whole data and make
the best_* attributes available for that metric. If this is not needed, refit should 
be set to False explicitly. True was passed.
Run Code Online (Sandbox Code Playgroud)

  • 好的所以我得到的是,如果我给 refit='precision_score' ,那么它会给出最好的参数以获得最好的 precion 分数 (6认同)
  • 完全正确!只是补充一下,您可以在拟合 gridsearch 后使用 `lr_grid.cv_results_` 或更具可读性的 `pd.DataFrame(lr_grid.cv_results_)` 访问所有拟合和分数 (3认同)
  • 非常感谢:) 它帮助我确认了很多。 (2认同)