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 supporta 0.00 0.00 0.00 1b 0.00 0.00 0.00 0c 1.00 0.33 0.50 3accuracy 0.25 4macro 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/21 1.00 1.00 1.00 2 2/22 0.50 0.50 0.50 2 1/23 1.00 1.00 1.00 1 1/14 0.00 0.00 0.00 2 0/1micro avg 0.75 0.67 0.71 9 (1+2+3)/(2+3+3)=0.75macro 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.67samples avg 0.72 0.64 0.67 9 (1/2+2/3+3/3)/3=0.72
| 表头 | precision | recall | f1-score | support | precision计算方式(自加) |
|---|---|---|---|---|---|
| 0 | 1.000 | 1.000 | 1.000 | 2 | 2/2 |
| 1 | 1.000 | 1.000 | 1.000 | 2 | 2/2 |
| 2 | 0.500 | 0.500 | 0.500 | 2 | 1/2 |
| 3 | 1.000 | 1.000 | 1.000 | 1 | 1/1 |
| 4 | 0.000 | 0.000 | 0.000 | 2 | 0/1 |
| micro avg | 0.75 | 0.67 | 0.71 | 9 | (1+2+3)/(2+3+3) |
| macro avg | 0.70 | 0.70 | 0.70 | 9 | (1+1+0.5+1+0)/5 |
| 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 |
| samples avg | 0.72 | 0.64 | 0.67 | 9 | (1/2+2/3+3/3)/3 |
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
