【问题标题】:F1 score values different for F1 score metric and classification report sklearnF1分数指标和分类报告sklearn的F1分数值不同
【发布时间】:2020-05-04 05:53:46
【问题描述】:

我正在尝试分析我的结果,因此我在 sklearn 上使用了 F1 分数指标和分类报告。显示的结果完全不同,与平均类型无关。 它根本不匹配。 我的验证数据示例

F1 分数 0.7666666666666667

但是分类报告结果是:

  report       precision recall  f1-score   support
       0       0.16      0.57      0.25         7
       1       0.40      0.09      0.14        23
accuracy                           0.20        30



macro avg      precision: 0.28, recall:0.33,  f1score:0.20      support:30

weighted avg       precision:0.34      recall:0.20      f1score:0.17        support:30

任何帮助将不胜感激。 谢谢!

我的代码是: ` print('F1 score {}'.format(sklearn.metrics.f1_score(test_label, np.round(y_pred), average='micro'))'

分类报告是:

` print('F1 score {}'.format(sklearn.metrics.classification_report(test_label, np.round(y_pred), target_names=labels))´

labels 只是一个包含我的类标签的列表。

【问题讨论】:

  • 你的具体问题是什么?
  • 您能分享您的代码吗?
  • 对不起,我的问题是为什么 F1 分数有差异?我的代码也更新了。

标签: python python-3.x scikit-learn metrics


【解决方案1】:

当您计算 f1-score 时,您要求 scikit 计算平均值='micro',但分类报告会计算宏观和加权平均值。

试试print('F1 score {}'.format(sklearn.metrics.f1_score(test_label, np.round(y_pred), average='macro'))

【讨论】:

  • 感谢您的回复,我已经尝试过了,但值仍然不匹配或者甚至不匹配。
猜你喜欢
  • 2020-06-17
  • 1970-01-01
  • 2017-05-07
  • 2017-09-11
  • 2019-09-01
  • 1970-01-01
  • 2017-11-07
  • 2020-10-21
  • 2020-02-22
相关资源
最近更新 更多