classification_report指标详解

sklearn的classification_report详解
precision、recall 、f1-score这三个基本就不介绍了,主要介绍平均的一些指标micro avg、macro avg、weighted avg、samples avg、accuracy

单分类

accuracy:正确率,分类正确样本数/总样本数
macro avg:用每一个类别对应的precision、recall、f1-score直接平均
weighted avg:用每一类别个数的权重乘对应类别指标

例子

from sklearn.metrics import classification_report
print(classification_report([3,3,3,1], [1,3,1,2], target_names=['a', 'b', 'c']))
              precision    recall  f1-score   support

           a       0.00      0.00      0.00         1
           b       0.00      0.00      0.00         0
           c       1.00      0.33      0.50         3

    accuracy                           0.25         4
   macro avg       0.33      0.11      0.17         4
weighted avg       0.75      0.25      0.38         4

多分类

多分类中增加了两个指标micro avg、samples avg是针对样本计算的,其他指标是针对标签计算的

micro avg:针对样本,对每一个样本所有类别的TP加起来除以所有类别(TP+FP)
macro avg: 用每一个类别对应的precision、recall、f1-score直接平均
weighted avg:用每一类别个数的权重乘对应类别指标
samples avg:针对样本,首先对每一个样本计算precision、recall指标然后对样本进行平均

例子

from sklearn.metrics import classification_report
y_true = np.array([[1, 0, 1, 0, 0],
                   [0, 1, 0, 1, 1],
                   [1, 1, 1, 0, 1]])
y_pred = np.array([[1, 0, 0, 0, 1],
                   [0, 1, 1, 1, 0],
                   [1, 1, 1, 0, 0]])
print(classification_report(y_true, y_pred))
              precision    recall  f1-score   support  precision计算方式(自加)

           0       1.00      1.00      1.00         2    2/2
           1       1.00      1.00      1.00         2    2/2
           2       0.50      0.50      0.50         2    1/2
           3       1.00      1.00      1.00         1    1/1
           4       0.00      0.00      0.00         2    0/1

   micro avg       0.75      0.67      0.71         9    (1+2+3)/(2+3+3)=0.75
   macro avg       0.70      0.70      0.70         9  (1+1+0.5+1+0)/5=0.7
weighted avg       0.67      0.67      0.67         9  (2/9)*1+(2/9)*1+(2/9)*0.5+(1/9)*1+(2/9)*0=0.67
 samples avg       0.72      0.64      0.67         9  (1/2+2/3+3/3)/3=0.72

表头precisionrecallf1-scoresupportprecision计算方式(自加)01.0001.0001.00022/211.0001.0001.00022/220.5000.5000.50021/231.0001.0001.00011/140.0000.0000.00020/1micro avg0.750.670.719(1+2+3)/(2+3+3)macro avg0.700.700.709(1+1+0.5+1+0)/5weighted avg0.670.670.679(2/9)1+(2/9)1+(2/9)0.5+(1/9)1+(2/9)*0samples avg0.720.640.679(1/2+2/3+3/3)/3

Original: https://blog.csdn.net/qq_22526061/article/details/124834674
Author: qq_652530495
Title: classification_report指标详解

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/661938/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球