Precision、Recall和F1可以是同一个值吗?

Can the Precision, Recall and F1 be the same value?

我目前正在处理 ML 分类问题,我正在使用 sklearn 库的以下导入和相应代码计算 Precision、Recall 和 F1,如下所示。

from sklearn.metrics import precision_recall_fscore_support

print(precision_recall_fscore_support(y_test, prob_pos, average='weighted'))

结果

0.8806451612903226, 0.8806451612903226, 0.8806451612903226

是否有可能为 ML 分类问题的精度、召回率和 F1 这 3 个都获得相同的值?

如能对此作出任何说明,我们将不胜感激。

是的,这是可能的。让我们假设二进制分类

Pr = TP  / (TP + FP); Re = (TP + FN); F1 = 2TP / (2TP + FP + FN)

Pr = Re = F1 的简单解是 TP = 0。所以我们知道精度、召回率和 F1 通常可以具有相同的值。现在,这不适用于您的特定结果。如果我们求解方程组,我们会找到另一个解:FP = FN。因此,如果误报数与漏报数相同,则所有三个指标都具有相同的值。

对于多类分类问题,我们有

F1 = 2 * (Pr * Re) / (Pr + Re)

如果 Pr = Re,所有三个指标同样相同。

这似乎是因为选项 - average='weighted'

参考:https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html

'weighted': Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters ‘macro’ to account for label imbalance; it can result in an F-score that is not between precision and recall.