precision vs recall
precision:精确率。在被判断为真的样例中,实际为真的样例比例。
P=true positive/predicted positiveP=true \,positive/predicted \,positiveP=truepositive/predictedpositive
recall:召回率。在实际为真的样例中,被判断为真的样例比例。
R=true positive/actual positiveR=true \,positive/actual \,positiveR=truepositive/actualpositive
precision越高,假阳性出现的概率越低。
recall越高,假阴性出现的概率越低。
e.g.cat vs non-cat 分类器
空白 | 判断是猫 | 判断非猫 |
---|---|---|
是猫 | x1 | x2 |
非猫 | y1 | y2 |
P=x1/(x1+x2)P=x1/(x1+x2)P=x1/(x1+x2)
R=x1/(x1+y1)R=x1/(x1+y1)R=x1/(x1+y1)
控制precision和recall
if yhat>=threshold,then y=1if \,y_{hat}>=threshold,then\, y=1ifyhat>=threshold,theny=1
else,y=0else, y=0else,y=0
降低threshold:更不容易被判断为阴性,减少假阴性,recall变大
提高threshold:更不容易被判断为阳性,减少假阳性,precision变大
用一个数衡量算法的效果
F1−score=2/(1/P+1/R)F1- score=2/(1/P+1/R)F1−score=2/(1/P+1/R)
F1−scoreF1-scoreF1−score越大,效果越好。
为什么不用算术平均?
F2−score=(P+R)/2F2-score=(P+R)/2F2−score=(P+R)/2
假设一个算法,无论对什么输入,都输出y=0
那么这个算法的假阳性发生概率为0,P=1;没有true positive,R=0。
因此,F2-score的成绩还是不错的,甚至要超过一些比它更有用的算法,因为R大大拉高了平均成绩。
但是在调和平均中,P,R任何一方为0,都会导致分母无穷大,从而F1-score=0