继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

python计算auc指标

守着星空守着你
关注TA
已关注
手记 211
粉丝 39
获赞 266

本文和大家分享的主要是python计算auc指标相关内容,一起来看看吧,希望对大家学习python http://www.maiziedu.com/land/python/有所帮助。

  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

2 from sklearn.metrics import roc_auc_score

3 y_true = np.array([0, 0, 1, 1])

4 y_scores = np.array([0.1, 0.4, 0.35, 0.8])

5 roc_auc_score(y_true, y_scores)

  输出:0.75

  3.计算roc曲线

1 import numpy as np

2 from sklearn import metrics

3 y = np.array([1, 1, 2, 2])   #实际值

4 scores = np.array([0.1, 0.4, 0.35, 0.8])  #预测值

5 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 ])

原文链接:http://www.apkbus.com/blog-907513-68288.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP