99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829
麥子學(xué)院 頭像
蘋果6袋
6
麥子學(xué)院

Python的auc指標(biāo)如何計(jì)算?

發(fā)布時(shí)間:2017-07-15 21:53  回復(fù):0  查看:3665   最后回復(fù):2017-07-15 21:53  

本文和大家分享的主要是python計(jì)算auc指標(biāo)相關(guān)內(nèi)容,一起來看看吧,希望對大家學(xué)習(xí)python有所幫助。

  1.安裝scikit-learn

  1.1Scikit-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、SciPypython并且均滿足1.1中所需的條件,那么可以直接運(yùn)行sudo

  pip install - U scikit - learn

  執(zhí)行安裝。

  2.計(jì)算auc指標(biāo)

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.計(jì)算roc曲線

1 import numpy as np

2 from sklearn import metrics

3 y = np.array([1, 1, 2, 2])   #實(shí)際值

4 scores = np.array([0.1, 0.4, 0.35, 0.8])  #預(yù)測值

5 fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)  #pos_label=2,表示值為2的實(shí)際值為正樣本

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

 

 

來源:博客園

您還未登錄,請先登錄

熱門帖子

最新帖子

?