【问题标题】:Why do i get different precision, recall and f1 score for different methods of calculating the macro avearage为什么计算宏观平均值的不同方法会得到不同的精度、召回率和 f1 分数
【发布时间】:2019-12-07 15:16:09
【问题描述】:

我使用两种方法计算了我的分类的 P、R 和 F1 的宏观平均值。方法一是

print("Macro-Average Precision:", metrics.precision_score(predictions, test_y, average='macro'))
print("Macro-Average Recall:", metrics.recall_score(predictions, test_y, average='macro'))
print("Macro-Average F1:", metrics.f1_score(predictions, test_y, average='macro'))

给出了这个结果:

Macro-Average Precision: 0.6822
Macro-Average Recall: 0.7750
Macro-Average F1: 0.7094

方法二是:

print(classification_report(y_true, y_pred))

给出了这个结果:

precision    recall  f1-score   support
       0       0.55      0.25      0.34       356
       1       0.92      0.96      0.94      4793
       2       0.85      0.83      0.84      1047
accuracy                           0.90      6196

macro avg       0.78      0.68      0.71      6196
weighted avg       0.89      0.90      0.89      6196

我希望这两种方法的输出是相同的,因为它们是在同一次运行中同时生成的。 有人可以解释为什么会发生这种情况或某处是否有错误?

【问题讨论】:

    标签: scikit-learn multiclass-classification precision-recall


    【解决方案1】:

    据我从分类报告结果中可以看出,您有多个类。

    如果您检查 documentation 以获得度量模块中的单个函数,默认参数将类“1”视为默认正类。

    我认为可能发生的情况是,在您的第一次计算中,它是 One 与所有计算(0 和 2 是负类,1 是正类)。在第二种情况下,您实际上是在考虑真正的多类情况。

    【讨论】:

      猜你喜欢
      • 2021-05-29
      • 2019-09-30
      • 1970-01-01
      • 2019-06-27
      • 2019-11-20
      • 2012-01-19
      • 1970-01-01
      • 2019-11-16
      • 2021-04-09
      相关资源
      最近更新 更多