首页 技术 正文
技术 2022年11月14日
0 收藏 410 点赞 3,800 浏览 602 个字

利用sklearn画AUC曲线

from sklearn.metrics import roc_curve
labels=[1,1,0,0,1]
preds=[0.8,0.7,0.3,0.6,0.5]
fpr, tpr, thresholds = roc_curve(labels, preds)

print(fpr)
print(tpr)
print(thresholds)

结果:

[0. 0. 0.5 0.5 1. ]

[0.33333333 0.66666667 0.66666667 1. 1. ]

   [0.8 0.7 0.6 0.5 0.3]

计算AUC面积

auc=0
init_x=0
for x,y in zip(fpr,tpr):
if x!=init_x:
auc+=(x-init_x)*y
init_x=x
print(auc)或者直接利用下面语句直接计算即可
from sklearn.metrics import roc_auc_score
auc = roc_auc_score(labels, preds)

画出AUC图

plt.plot(fpr,tpr)
plt.title("auc=%.4f"%(auc))
plt.xlabel("False Positive Rate")
plt.ylabel("True Positive Rate")
plt.fill_between(fpr, tpr, where=(tpr>0), color='green', alpha=0.5)
plt.show()

AUC画图与计算

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,117
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927