TP Rate ,FP Rate, Precision, Recall, F-Measure, ROC Area,

TP Rate ,FP Rate, Precision, Recall, F-Measure, ROC Area,

https://www.zhihu.com/question/30643044

T/F表示 true/false  表示预测的是不是对的
P/N表示 positive/negative  表示实际数据是正样本还是负样本
P/N表示 positive/negative  表示预测数据是正样本还是负样本
 
TP: 预测为1, 实际为1,预测正确
FP: 预测为1, 实际为0,预测错误
TN: 预测为0,实际为0,预测正确
FN: 预测为0, 实际为1,预测错误

True Positive (真正, TP)被模型预测为正样本,实际为正样本;

False Positive (假正, FP)被模型预测为正样本, 实际为负样本;

True Negative(真负 , TN)被模型预测为负样本,实际为负样本 ;

False Negative(假负 , FN)被模型预测为负样本,实际为正样本;

举例:

实际样本标签  actual_issame             = [1 1 1 1 1 1 0 0 0 0 0]

预测样本结果  predict_issame            = [1 1 0 1 0 1 1 0 0 0 0]

实际样本标签  actual_issame_not       = [0 0 0 0 0 1 1 1 1 1 1]

预测样本结果  predict_issame_not      = [0 0 1 0 1 0 0 1 1 1 1]

正样本个数为6

负样本个数为5

TP + FN = 正样本个数为6

FP + TN = 负样本个数为5

TP = 4  TN = 4  FP = 1  FN = 2

贴一段计算代码

predict_issame = np.less(dist, threshold)
tp = np.sum(np.logical_and(predict_issame, actual_issame))
fp = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame)))
tn = np.sum(np.logical_and(np.logical_not(predict_issame), np.logical_not(actual_issame)))
fn = np.sum(np.logical_and(np.logical_not(predict_issame), actual_issame))

tpr = 0 if (tp+fn==0) else float(tp) / float(tp+fn)
fpr = 0 if (fp+tn==0) else float(fp) / float(fp+tn)
acc = float(tp+tn)/dist.size
return tpr, fpr, acc

以上面的为例

TP = 4  TN = 4  FP = 1  FN = 2

tpr = TP /(TP + FN)= 4/(4+2) = 66.7%

fpr = FP /(FP + TN)= 1 / (1+4) = 20%

acc = (tp+tn) / (总的样本个数) = (4+4) / 11 = 72.7%

True Positive Rate(真正率 , TPR)或灵敏度(sensitivity) 
   TPR = TP /(TP + FN)

True Negative Rate(真负率 , TNR)或特指度(specificity) 
   TNR = TN /(TN + FP) 

False Positive Rate (假正率, FPR) 
   FPR = FP /(FP + TN) 

False Negative Rate(假负率 , FNR) 
   FNR = FN /(TP + FN) 

还有另外两个评价指标,针对正样本的评价指标

准确率precision: TP/ (TP+FP) 预测为正样本中有多少是真正的正样本
召回率recall: TP/ (TP +FN) 正样本有多少被成功预测为正样本
错误接受率: FAR: 同FPR 

ROC曲线: TPR与FPR博弈的过程曲线,在不同阈值判决下

分类器希望的是TPR越大,FPR越小,

降低阈值可以使TPR变大,FPR也会越大

提高阈值可以降低FPR,但是TPR会降低

实际中需要根据实际场景进行合理选择阈值,

比如在人脸识别支付的时候,对FPR比较敏感,FPR越小,错误接收的用户可能性越小,用户的钱财越安全, 这个时候,可以提高阈值,降低FPR,TPR也会下降(用户体验会下降)。

在如精准营销领域的商品推荐模型,模型目的是尽量将商品推荐给感兴趣的用户,若用户对推荐的商品不感兴趣,也不会有很大损失,因此此时TPR相对FPR更重要,这个时候可以降低阈值。

 

 

原文地址:https://www.cnblogs.com/adong7639/p/8883158.html