1. 混淆矩阵和统计量
用缩写分别表示图中 各个单元格中表示的个体数量,
2. 评测指标的定义
对随机提取的样本,设其分别在实际类别和预测类别时的随机变量用Y和Yhat表示。另外用+和-分别表示正(positive)和负(negative)的类别,则定义各种指标量:
2.1 类别与整体的比率
acc: Accuracy, 准确度,(准确性)
P(Yhat = Y). 估计为: (TP+TN)/ALL.
err: Error rate, 错误率
P(Yhat != Y). 估计为: (FP+FN)/ALL.
rpp: Rate of positive predictions.
P(Yhat = +). 估计为: (TP+FP)/ALL.
rnp: Rate of negative predictions.
P(Yhat = -). 估计为: (FN+TN)/ALL.
2.2 从实际类别观察
fpr: False positive rate, 错认率
P(Yhat = + | Y = -). 估计为: FP/N = FP/(FP+TN).
tpr: True positive rate, 命中率
P(Yhat = + | Y = +). 估计为: TP/P = TP/(TP+FN).
tnr: True negative rate,
P(Yhat = - | Y = -). 估计为: TN/N = TN/(FP+TN).
fnr: False negative rate,
P(Yhat = - | Y = +). 估计为: FN/P = FN/(TP+FN).
fall: Fallout, 虚报率,与fpr相同
miss: Miss rate, 漏报率,与fnr相同
sens: Sensitivity, 敏感性,与tpr相同,(灵敏性)
spec: Specificity, 特异性,与tnr相同
关系:
fpr+tnr=1
tpr+fnr=1
2.3 从预测类别观察
ppv: Positive predictive value, 有效认定率
P(Y = + | Yhat = +). 估计为: TP/(TP+FP).
npv: Negative predictive value, 有效排除率
P(Y = - | Yhat = -). 估计为: TN/(TN+FN).
pcfall: Prediction-conditioned fallout.
P(Y = - | Yhat = +). 估计为: FP/(TP+FP).
pcmiss: Prediction-conditioned miss.
P(Y = + | Yhat = -). 估计为: FN/(TN+FN).
关系:
ppv+pcfall=1
npr+pcmiss=1
2.4 综合观察的指标对
以上已经定义了公式,
rec: recall, 查全率,与tpr相同,(命中率)
P(Yhat = + | Y = +). 估计为: TP/P = TP/(TP+FN).
prec: precision, 查准率,与ppv相同,(精确性,有效认定率)
P(Y = + | Yhat = +). 估计为: TP/(TP+FP).
2.5 其它的指标
lift: Lift value, 提升值
P(Y = + | Yhat = +)/P(Y = +). 估计为: ppv/(P/ALL),也就是查准率与实际正向比率之间的比值,值越大表示预测正向结果越准确。
P(Yhat = + | Y = +)/P(Yhat = +). 估计为: tpr/rpp
response: 响应率,与ppv相同
P(Y = + | Yhat = +). 估计为: TP/(TP+FP).
3. 重要的性能图
根据前面定义的各个性能指标,在各个专业领域,有其需要的性能评测图。
下面各个说明中,measure指y坐标值,x.measure则指x坐标值
3.1 性能曲线
ROC curves: measure="tpr", x.measure="fpr".
Precision/recall graphs: measure="prec", x.measure="rec".
Sensitivity/specificity plots: measure="sens", x.measure="spec".
3.2 提升曲线
(累积)增益曲线 (Cumulative) Gain charts: measure="tpr", x.measure="rpp".
提升曲线 Lift charts: measure="lift", x.measure="rpp".
响应曲线 Response charts: measure="ppv", x.measure="rpp".
3.3 利润曲线
(标准)利润曲线 (Standardized) Profit charts: measure="tpr"-"fpr", x.measure="rpp"
设预测与实际相同时(TP),获得收益(Revenue) pt;而预测与实际不同时(FP),损失成本(Cost) pf。于是计算利润(Profit)率为:
measure="TP*pt/ALL"-"FP*pf/ALL"
定制利润曲线 Customized Profit charts: measure="TP*pt/ALL"-"FP*pf/ALL", x.measure="rpp"
可以计算:measure="TP/P*P/ALL*pt"-"FP/N*N/ALL*pf"
="tpr*P/ALL*pt"-"fpr*N/ALL*pf"
所以,当取pt=ALL/P, pf=ALL/N时,Customized Profit就是Standardized Profit了
3.4 Lorenz曲线
Lorenz "Good": measure="1-tpr"="fnr", x.measure="1-rpp"="rnp".
Lorenz "Bad": measure="1-fpr"="tnr", x.measure="1-rpp"="rnp".
KS指标(Kolmogorov-Smirnov indicator)= max(tnr-fnr), 显然KS也是Profit charts的最大值
4. 实例代码
这里给出用R-language及其ROCR包,得到以上的各种性能图
library(ROCR)
old<-read.csv("oldsamples.txt",header=T)
pred<-prediction(old[[2]],old[[1]])
rm(old)
# ROC curves
perf<-performance(pred,"tpr","fpr")
plot(perf)
# Precision/recall graphs
perf<-performance(pred,"prec","rec")
plot(perf)
# Sensitivity/specificity plots
perf<-performance(pred,"sens","spec")
plot(perf)
# Gain, Lift, and Response Charts
perf<-performance(pred,"tpr","rpp")
plot(perf)
perf<-performance(pred,"lift","rpp")
plot(perf)
perf<-performance(pred,"ppv","rpp")
plot(perf)
# Lorenz "Good" and "Bad" Curves
perf<-performance(pred,"fnr","rnp")
perf@y.name<-"Lorenz Good and Bad"
plot(perf)
perf<-performance(pred,"tnr","rnp")
plot(perf,add=T)
perf<-performance(pred,"tnr","fnr")
profit<-perf@y.values[[1]]-perf@x.values[[1]]
KS<-max(profit)
# (Standardized) Profit Charts
perf<-performance(pred,"tpr","fpr")
profit<-perf@y.values[[1]]-perf@x.values[[1]]
KS<-max(profit)
perf<-performance(pred,"rnp","rpp")
perf@y.values[[1]]<-profit
perf@y.name<-"Profit Rate"
plot(perf)
5. 主要参考资料