栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

classification

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

classification

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/2
11.0001.0001.00022/2
20.5000.5000.50021/2
31.0001.0001.00011/1
40.0000.0000.00020/1
micro avg0.750.670.719(1+2+3)/(2+3+3)
macro avg0.700.700.709(1+1+0.5+1+0)/5
weighted avg0.670.670.679(2/9)*1+(2/9)*1+(2/9)*0.5+(1/9)*1+(2/9)*0
samples avg0.720.640.679(1/2+2/3+3/3)/3
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/915855.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号