当前位置:网站首页>PR曲线和ROC曲线概念及其区别
PR曲线和ROC曲线概念及其区别
2022-07-02 16:58:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
知识点
Precision=TP/(TP+FP) Recall=TP/(总的正样本)=TP/(TP+FN) # 这个时候的 TPR=TP/(TP+FN)=Recall # 真正例率 FPR=FP/(TN+FP) # PR曲线 横Recall,纵Precision PR曲线的绘制 场景:有限样本。 方法:固定分类阈值(比如0.5),对分类器的预测结果按照置信度进行降序排序,然后按此顺序对样例进行预测,每次可以计算出当前的查全率(Recall)和查准率(Precision),然后以此作图,绘制出P-R曲线。(疑惑??:P-R曲线是按照固定的分类阈值,还是按照西瓜书所讲,按照置信度降序的顺序,逐个把样本作为正例进行预测??我做商汤的笔试题,是采取固定分类阈值的策略) ROC曲线 横FPR,纵TPR,理想的情况是TPR=1,FPR=0,一般来说,FPR增大,则TPR也会跟着增大。 ROC曲线的绘制: 场景:有限样本。 方法:卡阈值,对学习器的预测结果排序,排在前面的是最可能为正例的样本,最后的是最不可能的样本,然后计算不同阈值下的TPR和FPR值,绘制出曲线。 卡阈值作为正负样本的判定依据,阈值较高时,Precision比较大,阈值较低时,Recall较大。(推荐的话,想Precision较大,用户希望排名靠前的推荐是自己想要的,刑侦的话希望Recall较大,不错过一个犯人) AUC:ROC曲线下面积。 PR和ROC曲线应用范围: 1.当正负样本比例差不多的时候,两者区别不大。 2.PR曲线比ROC曲线更加关注正样本,而ROC则兼顾了两者。 3.AUC越大,反映出正样本的预测结果更加靠前。(推荐的样本更能符合用户的喜好) 4.当正负样本比例失调时,比如正样本1个,负样本100个,则ROC曲线变化不大,此时用PR曲线更加能反映出分类器性能的好坏。 5.PR曲线和ROC绘制的方法不一样。
PR曲线和ROC曲线区别参考链接:http://www.fullstackdevel.com/computer-tec/data-mining-machine-learning/501.html
附:商汤计算PR题
#-*-coding:utf-8-*-
def s4j5(a):
a1=float(int(a*100))
tag=a*100-a1
if tag>=0.5:
return((a1+1)/100)
else:
return(a1/100)
N = int(raw_input())
recall = 0.0
labelCon = []
totalPos = 0
for i in range(N):
temp = [xx for xx in raw_input().strip().split()]
target, confidence = int(temp[0]), float(temp[0])
labelCon.append([target, confidence])
if target==1:
totalPos+=1
count = 0
posCount = 0
correctCount = 0
FP = 0
FN = 0
someRecallDict = {0.3:0,
0.4:0,
0.5:0,
0.6:0,
0.7:0,
0.8:0,
0.9:0}
someRecall = [0.3,0.4,0.5,0.6,0.7,0.8,0.9]
res = []
posId = 0
predictPos = 0
for target, confidence in labelCon:
count+=1
if confidence>=0.5:
predictPos+=1 # 预测为正类的样本个数
if target==0:
if confidence>=0.5:
FP+=1
if target==1:
posCount+=1
if confidence>=0.5:
correctCount+=1
else:
FN+=1
recall = float(correctCount)/float(totalPos)
if posId<=6:
if recall==someRecall[posId] and someRecallDict[someRecall[posId]]==0:
someRecallDict[someRecall[posId]]=1
posId+=1
precision = int(str(s4j5(float(correctCount)/float(predictPos))*100).split('.')[0])
res.append(precision)
for i in res:
print(i)
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148428.html原文链接:https://javaforall.cn
边栏推荐
- Wechat nucleic acid detection appointment applet system graduation design completion (5) task statement
- RDK simulation experiment
- Nm02 nm module call sequence diagram and code interpretation independent of bus protocol
- SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
- Clé de cartographie vimium
- Web chat tool
- paddlepaddle 28 搭建基于卷积的自动编码机
- Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
- Memory mapping of QT
- Leetcode 面试题 17.01. 不用加号的加法
猜你喜欢
Leetcode 面试题 17.04. 消失的数字
一款简约PHP个人发卡程序V4.0版本
MySQL installation and configuration
微信小程序视频分享平台系统毕业设计毕设(5)任务书
【西北工业大学】考研初试复试资料分享
NM01-独立于总线协议的NM模块功能概述与API定义
Use Zadig to build a continuous delivery platform from 0 to 1
Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案
Wechat applet video sharing platform system graduation design (3) background function
夜神模擬器+Fiddler抓包測試App
随机推荐
Unity learning shader notes [81] simple color adjustment post-processing (brightness, saturation, contrast)
呆错图床系统源码图片CDN加速与破J防盗链功能
iframe嵌套详解
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
Renren potential field method
Intelligent hydropower meter energy consumption monitoring cloud platform
C # detect whether the picture is rotated and modified to the true rotation
Simulateur nightGod + application de test de capture de paquets Fiddler
matplotlib的安装教程以及简单调用
Wechat applet video sharing platform system graduation design completion (1) development outline
em120.gige. h
RDK仿真实验
Vimium mapping key
Leetcode interview question 17.04 Vanishing numbers
QQmlApplicationEngine
面试,关于线程池的那些事
Web chat tool
Leetcode interview question 16.15 Abacus wonderful calculation
Embedded ~ introduction
微信小程序视频分享平台系统毕业设计毕设(2)小程序功能