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. jsp實(shí)現(xiàn)簡(jiǎn)單用戶7天內(nèi)免登錄2. xml文件的結(jié)構(gòu)解讀第1/2頁(yè)3. ASP 連接Access數(shù)據(jù)庫(kù)的登陸系統(tǒng)4. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)5. 怎樣打開XML文件?xml文件如何打開?6. ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識(shí))7. 父div高度不能自適應(yīng)子div高度的解決方案8. ASP.NET MVC實(shí)現(xiàn)登錄后跳轉(zhuǎn)到原界面9. ASP.NET MVC使用JSAjaxFileUploader插件實(shí)現(xiàn)單文件上傳10. 讓 Asp 與 XML 交互
