当我们使用 sklearn.metric.classification_report 工具对模型的测试结果进行评价时,会输出如下结果:
对于 精准率(precision )、召回率(recall)、f1-score,他们的计算方法很多地方都有介绍,这里主要讲一下micro avg、macro avg 和weighted avg 他们的计算方式。
1、宏平均 macro avg:
对每个类别的 精准、召回和F1 加和求平均。
精准macro avg
=(P_no+P_yes) / 2
=(0.24+0.73) / 2 = 0.48
2、微平均 micro avg:
不区分样本类别,计算整体的 精准、召回和F1
精准macro avg
=(P_nosupport_no+P_yessupport_yes) / (support_no+support_yes)
=(0.247535+0.7322462) / (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)