在 Gridsearchcv 中评分

Scoring in Gridsearch CV

我刚开始在 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)

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

gridsearch 是否使用它来根据这些评分值为我们提供优化的参数....比如为了获得最佳精度评分,它会找到最佳参数或类似的东西?

它计算可能参数的精度、召回率、准确性并给出结果,现在的问题是如果这是真的,那么它select基于精度、召回率或准确性的最佳参数?以上说法是否属实?

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

但是,如果不选择 refit 使用哪个分数,您就不能让网格搜索自动适合 return best_estimator_,它会抛出以下内容错误:

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.

What is the intent of using these values, i.e. precision, recall, accuracy in scoring?

以防万一您的问题还包括 "What are precision, recall, and accuracy and why are they used?"...

  • 准确性 =(正确预测的数量)/(总预测)
  • 精度=(真阳性)/(真阳性+假阳性)
  • 召回率=(真阳性)/(真阳性+假阴性)

真阳性是对真的预测是正确的,假阳性是对真的预测是错误的,假阴性是对假的预测是错误的。

召回率和精度在处理不平衡数据集时是有用的指标(即,有很多标签为“0”的样本,但标签为“1”的样本要少得多。

召回率和精确率还会导致稍微复杂一些的评分指标,例如 F1_score(和 Fbeta_score),它们也非常有用。

这里 great article 解释了召回率和精确率的工作原理。