python計算auc的方法
1、安裝scikit-learn
1.1 Scikit-learn 依賴
Python (>= 2.6 or >= 3.3), NumPy (>= 1.6.1), SciPy (>= 0.9).分別查看上述三個依賴的版本:
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中所需的條件,那么可以直接運行sudo
pip install - U scikit - learn
執(zhí)行安裝。
2、計算auc指標
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、計算roc曲線
import numpy as npfrom sklearn import metricsy = np.array([1, 1, 2, 2]) #實際值scores = np.array([0.1, 0.4, 0.35, 0.8]) #預(yù)測值fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2) #pos_label=2,表示值為2的實際值為正樣本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計算auc的方法的文章就介紹到這了,更多相關(guān)python如何計算auc內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python 實現(xiàn)勞拉游戲的實例代碼(四連環(huán)、重力四子棋)2. Python+unittest+requests 接口自動化測試框架搭建教程3. Java GZip 基于內(nèi)存實現(xiàn)壓縮和解壓的方法4. jsp+servlet簡單實現(xiàn)上傳文件功能(保存目錄改進)5. JavaScript數(shù)據(jù)結(jié)構(gòu)之雙向鏈表6. 利用CSS制作3D動畫7. 一款功能強大的markdown編輯器tui.editor使用示例詳解8. 存儲于xml中需要的HTML轉(zhuǎn)義代碼9. SpringBoot+TestNG單元測試的實現(xiàn)10. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程
