python計(jì)算auc的方法
1、安裝scikit-learn
1.1 Scikit-learn 依賴
Python (>= 2.6 or >= 3.3), NumPy (>= 1.6.1), SciPy (>= 0.9).分別查看上述三個(gè)依賴的版本:
python -V
結(jié)果:
Python 2.7.3
python -c ’import scipy; print scipy.version.version’
scipy版本結(jié)果:
0.9.0
python -c 'import numpy; print numpy.version.version'
numpy結(jié)果:
1.10.2
1.2 Scikit-learn安裝
如果你已經(jīng)安裝了NumPy、SciPy和python并且均滿足1.1中所需的條件,那么可以直接運(yùn)行sudo
pip install - U scikit - learn
執(zhí)行安裝。
2、計(jì)算auc指標(biāo)
import numpy as npfrom sklearn.metrics import roc_auc_scorey_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、計(jì)算roc曲線
import numpy as npfrom sklearn import metricsy = np.array([1, 1, 2, 2]) #實(shí)際值scores = np.array([0.1, 0.4, 0.35, 0.8]) #預(yù)測(cè)值fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2) #pos_label=2,表示值為2的實(shí)際值為正樣本print fprprint tprprint thresholds
輸出:
array([ 0. , 0.5, 0.5, 1. ])array([ 0.5, 0.5, 1. , 1. ])array([ 0.8 , 0.4 , 0.35, 0.1 ])
到此這篇關(guān)于python計(jì)算auc的方法的文章就介紹到這了,更多相關(guān)python如何計(jì)算auc內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. PHP設(shè)計(jì)模式(四)原型模式Prototype實(shí)例詳解【創(chuàng)建型】2. SpringBoot 開發(fā)提速神器 Lombok+MybatisPlus+SwaggerUI3. python 爬取嗶哩嗶哩up主信息和投稿視頻4. Java向Runnable線程傳遞參數(shù)方法實(shí)例解析5. Python編寫nmap掃描工具6. PHP擴(kuò)展之APC——Alternative PHP Cache(可選PHP緩存)7. Java 基于UDP協(xié)議實(shí)現(xiàn)消息發(fā)送8. Android里巧妙實(shí)現(xiàn)緩存9. php5.6不能擴(kuò)展redis.so的解決方法10. 10個(gè)提供免費(fèi)PHP腳本下載的網(wǎng)站
