当前位置:网站首页>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
边栏推荐
- Embedded development board ~ description
- vimium映射鍵
- A good programmer is worth five ordinary programmers!
- 微信小程序视频分享平台系统毕业设计毕设(5)任务书
- 夜神模拟器+Fiddler抓包测试App
- Leetcode 面试题 17.04. 消失的数字
- matplotlib的安装教程以及简单调用
- Steamos 3.3 beta release, steam deck Chinese keyboard finally came
- Qt官方示例:Qt Quick Controls - Gallery
- Troubleshooting ideas that can solve 80% of faults
猜你喜欢

Wechat nucleic acid detection appointment applet system graduation design completion (4) opening report

微信核酸检测预约小程序系统毕业设计毕设(3)后台功能

Remember to use ternary expressions when switching transformations

微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板

RDK simulation experiment

Wechat applet video sharing platform system graduation design completion (1) development outline

拿起相机,便是最好的艺术疗愈

Relax again! These fresh students can settle directly in Shanghai

Esp32-c3 introductory tutorial question ⑩ - error: implicit declaration of function 'ESP_ blufi_ close‘;

Leetcode 面试题 16.15. 珠玑妙算
随机推荐
Wechat nucleic acid detection appointment applet system graduation design completion (5) task statement
微信小程序视频分享平台系统毕业设计毕设(3)后台功能
Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
Tower safety monitoring system unattended inclination vibration monitoring system
巴比特 | 元宇宙每日必读:一千块就能买一个虚拟主播?这是小企业的直播福音还是在“割韭菜”?...
Pit encountered during installation of laravel frame
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
又一所双非改考408,会爆冷么?南昌航空大学软件学院
Customize a loading instruction
Esp32-c3 introductory tutorial question ⑪ - ESP tls: create_ ssl_ handle failed, tls_ io_ instance->options. trusted_ certs null
Détends - toi encore! Ces nouveaux étudiants peuvent s'installer directement à Shanghai
Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
Babbitt | metauniverse daily must read: can you buy a virtual anchor for 1000 yuan? Is this the live gospel of small businesses or "cutting leeks"
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
Leetcode interview question 16.15 Abacus wonderful calculation
NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution
Wechat nucleic acid detection appointment applet system graduation design (2) applet function
QQmlApplicationEngine
铁塔安全监测系统 无人值守倾角振动监测系统
微信核酸检测预约小程序系统毕业设计毕设(3)后台功能