读懂sklearn的classification_report

本文介绍如何读懂classification_report的各个指标。

  • y_true为样本真实标记,y_pred为样本预测标记
  • support:某类别在测试数据中的样本个数,测试数据中有1个样本的真实标签为class 0
  • precision:模型预测的结果中有多少是预测正确的
  • micro avg:计算所有数据下的指标值,比如全部数据5个样本中有3个预测正确,故micro avg为0.6
  • macro avg:每个类别评估指标未加权的平均值,比如准确率的macro avg,(0.50+0.00+1.00)/3=0.5
  • weighted avg:加权平均,比如第一个值的计算方法,(0.50*1 + 0.0*1 + 1.0*3)/5 = 0.70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> from sklearn.metrics import classification_report
>>> y_true = [0, 1, 2, 2, 2]
>>> y_pred = [0, 0, 2, 2, 1]
>>> target_names = ['class 0', 'class 1', 'class 2']
>>> print(classification_report(y_true, y_pred, target_names=target_names))
precision recall f1-score support

class 0 0.50 1.00 0.67 1
class 1 0.00 0.00 0.00 1
class 2 1.00 0.67 0.80 3

micro avg 0.60 0.60 0.60 5
macro avg 0.50 0.56 0.49 5
weighted avg 0.70 0.60 0.61 5
------本文结束,欢迎收藏本站、分享、评论或联系作者!------
点击查看
赠人玫瑰 手有余香
0%