当我们使用 sklearn.metric.classification_report 工具对模型的测试结果进行评价时,会输出如下结果:
在这里插入图片描述对于 精准率(precision )、召回率(recall)、f1-score,他们的计算方法很多地方都有介绍,这里主要讲一下micro avg、macro avg 和weighted avg 他们的计算方式。

1、宏平均 macro avg:

对所有类别的平均

精准macro avg
=(P_no+P_yes) / 2
=(0.24+0.73) / 2 = 0.48

2、微平均 micro avg:
对数据集中的每⼀个实例不分类别进⾏统计建⽴全局混淆矩阵,然后计算相应指标:

精准micro avg = 召回micro avg = f1_micro avg
=(TP+TN) / (TP+FP+TN+FN)
=(0.54 * 7535 +0.42 * 22462 ) / (7535+22462)=0.45

3、加权平均 weighted avg:

是对宏平均的一种改进,考虑了每个类别样本数量在总样本中占比

精准加权weighted avg
=P_no * (support_no / support_all)+ P_yes * (support_yes / support_all)
=0.24*(7525 / 29997) + 0.73*(22462 / 29997)=0.61

参考:
分类问题的几个评价指标(Precision、Recall、F1-Score、Micro-F1、Macro-F1)
混淆矩阵(Confusion Matrix)分析
宏平均(macro avg)、微平均(micro avg)和加权平均(weighted avg)
【NLP】再看分类评估指标——宏平均,微平均

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐