色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

利用python畫出AUC曲線的實(shí)例

瀏覽:6日期:2022-08-05 11:41:00

以load_breast_cancer數(shù)據(jù)集為例,模型細(xì)節(jié)不重要,重點(diǎn)是畫AUC的代碼。

直接上代碼:

from sklearn.datasets import load_breast_cancerfrom sklearn import metricsfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.model_selection import train_test_splitimport pylab as pltimport warnings;warnings.filterwarnings(’ignore’)dataset = load_breast_cancer()data = dataset.datatarget = dataset.targetX_train,X_test,y_train,y_test = train_test_split(data,target,test_size=0.2)rf = RandomForestClassifier(n_estimators=5)rf.fit(X_train,y_train)pred = rf.predict_proba(X_test)[:,1]#############畫圖部分fpr, tpr, threshold = metrics.roc_curve(y_test, pred)roc_auc = metrics.auc(fpr, tpr)plt.figure(figsize=(6,6))plt.title(’Validation ROC’)plt.plot(fpr, tpr, ’b’, label = ’Val AUC = %0.3f’ % roc_auc)plt.legend(loc = ’lower right’)plt.plot([0, 1], [0, 1],’r--’)plt.xlim([0, 1])plt.ylim([0, 1])plt.ylabel(’True Positive Rate’)plt.xlabel(’False Positive Rate’)plt.show()

利用python畫出AUC曲線的實(shí)例

補(bǔ)充拓展:Python機(jī)器學(xué)習(xí)中的roc_auc曲線繪制

廢話不多說,直接上代碼

from sklearn.metrics import roc_curve,aucfrom sklearn.ensemble import RandomForestClassifierimport matplotlib.pyplot as pltfrom sklearn.model_selection import train_test_splitx_train,y_train,x_test,y_test=train_test_split(x,y,test_size=0.2)rf=RandomForestClassifier()rf.fit(x_train,y_train)rf.score(x_train,y_train)print(’trainscore:’+str(rfbest.score(x_train,y_train)))print(’testscore:’+str(rfbest.score(x_test,y_test)))y_score=rfbest.fit(x_train,y_train).predict_proba(x_test) #descision_function()不可用print(type(y_score))fpr,tpr,threshold=roc_curve(y_test,y_score[:, 1])roc_auc=auc(fpr,tpr)plt.figure(figsize=(10,10))plt.plot(fpr, tpr, color=’darkorange’,lw=2, label=’ROC curve (area = %0.2f)’ % roc_auc) ###假正率為橫坐標(biāo),真正率為縱坐標(biāo)做曲線plt.plot([0, 1], [0, 1], color=’navy’, lw=2, linestyle=’--’)plt.xlim([0.0, 1.0])plt.ylim([0.0, 1.05])plt.xlabel(’False Positive Rate’)plt.ylabel(’True Positive Rate’)plt.title(’Receiver operating characteristic example’)plt.legend(loc='lower right')plt.show()

以上這篇利用python畫出AUC曲線的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 玖玖国产在线 | 成年人免费视频观看 | 在线成人a毛片免费播放 | 亚洲精品精品一区 | 国产精品一区二区手机在线观看 | 在线国产高清 | 久草视 | 国产精品黄 | 国产视频二区 | 亚洲一区二区三区一品精 | 免费一级a毛片在线播 | 久草福利资源 | 亚洲国产精品免费观看 | 日韩欧美a级高清毛片 | 中文字幕亚洲一区二区va在线 | 国产精品高清在线观看地址 | 和日本免费不卡在线v | 亚洲福利国产精品17p | 一区二区三区四区产品乱码伦 | 国产欧美精品午夜在线播放 | 欧毛片| 日本香蕉一区二区三区 | 久久综合精品不卡一区二区 | 性色欧美xo影院 | 91探花福利精品国产自产在线 | 日本国产一区二区三区 | 欧美一区视频在线 | 亚洲天堂二区 | 久久国产亚洲 | 亚洲入口| 久草视频福利在线观看 | 一级做a爱片特黄在线观看免费看 | 国产a级高清版毛片 | 国产免费福利体检区久久 | 欧美精品日日鲁夜夜添 | 精品国产中文一级毛片在线看 | 成人亚洲精品一区 | 日本一级在线播放线观看免 | 日韩精品一区二区三区免费观看 | 美女国产福利视频 | 国产三级精品在线 |