文章目录
准确率判断的局限性
在大多部分分类问题中,我们常常采用准确率来判断一个模型的性能。即我们让模型在测试集上运行,比较模型的输出与真实情况,计算模型判断正确的比例。当这个比例较高,如 95 % 95\% 95%以上时,我们认为该模型有比较可靠的性能。
但对于一类比较特殊的数据,用准确率来衡量模型性能是不可靠的。如当测试集中 99 % 99\% 99%的数据都属于0类,仅 1 % 1\% 1%的数据属于1类时,一个只会输出0的算法也能达到 99 % 99\% 99%的正确率,这是我们不能接受的。这种类别极度不平衡的数据就称为“偏差类”(Skewed Classes)。因此,我们需要其他的指标帮助我们辨别此类伪算法。
查准率与召回率
查准率(precision,简写为P)与召回率(recall简写为R)便在这样的背景下应运而生。先定义真/假阴/阳性如下:
则查准率为
Precision
=
True positives
# predicted as positive
=
True positives
True positives + False positives
\text{Precision}=\frac{\text{True positives}}{\text{\# predicted as positive}}=\frac{\text{True positives}}{\text{True positives + False positives}}
Precision=# predicted as positiveTrue positives=True positives + False positivesTrue positives
召回率为
Recall
=
True positives
# actual positives
=
True positives
True positives + False negatives
\text{Recall}=\frac{\text{True positives}}{\text{\# actual positives}}=\frac{\text{True positives}}{\text{True positives + False negatives}}
Recall=# actual positivesTrue positives=True positives + False negativesTrue positives
(如果你学过随机数学,不难发现查准率与虚警率相对,召回率与漏警率相对)
通过这两个比率,我们就能更清晰的评估我们的模型。例如对于那些只会输出0的算法,它的召回率为0,很显然是一个不靠谱的算法。
平衡查准率与召回率
有了这两个比率作为判据,我们可以很方便地剔除一些离谱的算法。但对于这两项数据看起来都还不错的模型,我们又该如何选择呢?
一般情况下,我们的要求是平衡,即查准率与召回率都处在一个可以接受的高比率,不出现一个奇高而另一个很低的情况,所以采用平均值是行不通的。既然要对一个极小的值做出惩罚,我们可能会想到电阻的并联:并联的电阻值一定比两个单独的电阻值小,且一个小电阻的影响非常大。所以
F
1
F_1
F1公式
2
P
R
P
+
R
2\frac{PR}{P+R}
2P+RPR
成为一个比较泛用的评判指标,对于不同得到模型,我们一般选用
F
1
F_1
F1值较大的模型。