python计算auc指标实例
作者:jingxian 时间:2021-12-21 12:10:03
1、安装scikit-learn
1.1Scikit-learn 依赖
Python (>= 2.6 or >= 3.3),
NumPy (>= 1.6.1),
SciPy (>= 0.9).
分别查看上述三个依赖的版本,
python -V 结果:Python 2.7.3
python -c 'import scipy; print scipy.version.version' scipy版本结果:0.9.0
python -c "import numpy; print numpy.version.version" numpy结果:1.10.2
1.2 Scikit-learn安装
如果你已经安装了NumPy、SciPy和python并且均满足1.1中所需的条件,那么可以直接运行sudo pip install -U scikit-learn 执行安装。
2、计算auc指标
import numpy as np
from sklearn.metrics import roc_auc_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
roc_auc_score(y_true, y_scores)
输出:0.75
3、计算roc曲线
import numpy as np
from sklearn import metrics
y = np.array([1, 1, 2, 2]) #实际值
scores = np.array([0.1, 0.4, 0.35, 0.8]) #预测值
fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2) #pos_label=2,表示值为2的实际值为正样本
print fpr
print tpr
print thresholds
输出:
array([ 0. , 0.5, 0.5, 1. ])
array([ 0.5, 0.5, 1. , 1. ])
array([ 0.8 , 0.4 , 0.35, 0.1 ])
标签:python,auc计算
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python目标检测yolo1 yolo2 yolo3和SSD网络结构对比
2022-05-24 16:16:39
![](https://img.aspxhome.com/file/2023/6/92156_0s.jpg)
python通过pil模块将raw图片转换成png图片的方法
2021-08-25 00:37:31
Python实现TCP协议下的端口映射功能的脚本程序示例
2021-07-26 13:59:01
![](https://img.aspxhome.com/file/2023/2/93712_0s.png)
Python中选择结构实例讲解
2023-06-26 14:56:09
Python爬取科目四考试题库的方法实现
2023-02-14 00:29:39
![](https://img.aspxhome.com/file/2023/0/70220_0s.jpg)
Python字符串格式化输出代码实例
2021-11-09 16:44:22
讲解MySQL数据库字符集出错的解决方法
2008-12-02 14:32:00
asp截取字符串的两种应用
2009-08-19 17:11:00
Python面向对象之类和对象实例详解
2022-10-02 05:39:34
![](https://img.aspxhome.com/file/2023/2/86672_0s.png)
43个应当避免的Web设计错误
2007-09-30 12:57:00
python面试题之列表声明实例分析
2022-01-10 12:46:51
![](https://img.aspxhome.com/file/2023/5/84075_0s.png)
PyQt5中向单元格添加控件的方法示例
2023-10-20 05:08:48
![](https://img.aspxhome.com/file/2023/6/131396_0s.gif)
PHP入门教程之会话控制技巧(cookie与session)
2023-11-16 00:13:39
python 字典和列表嵌套用法详解
2022-04-12 10:58:12
基于Python使用永中文档转换服务的方式
2021-09-29 12:26:12
![](https://img.aspxhome.com/file/2023/7/95127_0s.png)
PHP crypt()函数的用法讲解
2023-06-13 03:08:05
![](https://img.aspxhome.com/file/2023/9/55389_0s.png)
简单了解python装饰器原理及使用方法
2023-11-02 11:55:02
解决项目pycharm能运行,在终端却无法运行的问题
2021-11-03 21:05:07
python双向链表实现实例代码
2023-05-16 09:38:54
![](https://img.aspxhome.com/file/2023/8/99218_0s.jpg)
二十种Python代码游戏源代码分享
2023-07-31 01:37:16
![](https://img.aspxhome.com/file/2023/5/60495_0s.gif)