分类模型的精确率(precision)与召回率(recall)(Python)
2016-01-11 17:21
1431 查看
TP:true positive,将正类预测为正类
FN:false negative,将正类预测为负类
FP:false positive,将负类预测为正类
TN:true negative,将负类预测为负类
![](https://img-blog.csdn.net/20140302141735812)
伪阳性率FPR(False Positive Rate,在真实为阴性的样本中,被误诊为阴性的比率):
FPR=FPFP+TN
真阳性率TPR(True Positive Rate,在真实为阳性的样本中,被正确诊断为阳性的比率为):
TPR=TPTP+FN
Precision(精确率):
P=TPTP+FP
Recall(召回率):
R=TPTP+FN
F1 score:
2F1=1P+1RF1=2PRP+R
FN:false negative,将正类预测为负类
FP:false positive,将负类预测为正类
TN:true negative,将负类预测为负类
伪阳性率FPR(False Positive Rate,在真实为阴性的样本中,被误诊为阴性的比率):
FPR=FPFP+TN
真阳性率TPR(True Positive Rate,在真实为阳性的样本中,被正确诊断为阳性的比率为):
TPR=TPTP+FN
Precision(精确率):
P=TPTP+FP
Recall(召回率):
R=TPTP+FN
F1 score:
2F1=1P+1RF1=2PRP+R
# y_true, y_pred # TP = (y_pred==1)*(y_true==1) # FP = (y_pred==1)*(y_true==0) # FN = (y_pred==0)*(y_true==1) # TN = (y_pred==0)*(y_true==0) # TP + FP = y_pred==1 # TP + FN = y_true==1 def precision_score(y_true, y_pred): return ((y_true==1)*(y_pred==1)).sum()/(y_pred==1).sum() def recall_score(y_true, y_pred): return ((y_true==1)*(y_pred==1)).sum()/(y_true==1).sum() def f1_score(y_true, y_pred): num = 2*precison_score(y_true, y_pred)*recall_score(y_true, y_pred) deno = (precision_score(y_true, y_pred)+recall_score(y_true, y_pred)) return num/deno
相关文章推荐
- python解析xml文件注意
- Unicode Tips
- python数字图像处理(2):图像的读取、显示与保存
- 自学Python一 迷茫中的开端!
- [151225] Python3 实现最大堆、堆排序,解决TopK问题
- Spark环境下的Kmeans-Python实现
- python豆瓣电影爬虫
- Python篇----命令行调用、输出log日志并打包的脚本
- Python进阶06-10
- [160111] Python学习记录
- Python使用wxPython报错解决方法
- Python转码问题
- [转]python pickle包,cPickle包 存储
- [转]python yield
- Python函数对象
- [转]Python核心模块——urllib模块
- 17个新手常见Python运行时错误
- 4.7.2. Keyword Arguments(关键字参数)
- python split()黑魔法
- python小点心--globals函数