介绍
这篇文章将为大家详细讲解有关怎么利用python画出AUC曲线,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
python主要用来做什么
python主要应用于:1,网络开发;2、数据科学研究;3,网络爬虫;4、嵌入式应用开发,5日游戏开发;6桌面应用开发。
<强>直接上代码:强>
得到sklearn.datasets import load_breast_cancer 得到sklearn import 指标 得到sklearn.ensemble import  RandomForestClassifier 得到sklearn.model_selection import  train_test_split import pylab  as plt import 预警;warnings.filterwarnings(& # 39;忽略# 39;) 时间=dataset load_breast_cancer () data =dataset.data target =dataset.target X_train、X_test y_train y_test =, train_test_split(数据、目标test_size=0.2) 时间=rf RandomForestClassifier (n_estimators=5) rf.fit (X_train y_train) 时间=pred rf.predict_proba (X_test) (: 1) # # # # # # # # # # # # #画图部分 玻璃钢,,tpr, threshold =, metrics.roc_curve (y_test, pred) 时间=roc_auc metrics.auc(玻璃钢,,tpr) plt.figure (figsize=(6,6)) plt.title (& # 39; Validation roc # 39;) plt.plot(玻璃钢,,tpr, & # 39; b # 39;,, label =, & # 39; Val AUC =, % 0.3 f # 39;, %, roc_auc) plt.legend (=loc & # 39; lower 对# 39;) plt.plot ([0, 1], [0, 1], & # 39; r - & # 39;) plt.xlim ([0, 1]) plt.ylim ([0, 1]) plt.ylabel (& # 39; True Positive 率# 39;) plt.xlabel (& # 39; False Positive 率# 39;) plt.show ()
<强>补充拓展:python机器学习中的roc_auc曲线绘制强>
废话不多说,直接上代码
得到sklearn.metrics import roc_curve, AUC 得到sklearn.ensemble import  RandomForestClassifier import matplotlib.pyplot  as plt 得到sklearn.model_selection import  train_test_split x_train、y_train x_test y_test=train_test_split (x, y, test_size=0.2) 射频=RandomForestClassifier () rf.fit (x_train y_train) rf.score (x_train y_train) 打印(& # 39;trainscore: & # 39; + str (rfbest.score (x_train y_train))) 打印(& # 39;testscore: & # 39; + str (rfbest.score (x_test y_test))) y_score=rfbest.fit (x_train y_train) .predict_proba (x_test), # descision_function()不可用 print(类型(y_score)) 玻璃钢,tpr,阈值=roc_curve (y_test y_score[1]:也) roc_auc=auc(玻璃钢,tpr) plt.figure (figsize=(10,10)) plt.plot(玻璃钢,,tpr,颜色=& # 39;darkorange& # 39;, lw=2,,标签=& # 39;ROC curve (area =, % 0.2 f) & # 39;, %, roc_auc), # # #假正率为横坐标,真正率为纵坐标做曲线 plt.plot([0, 1],[0, 1],颜色=& # 39;海军# 39;,,lw=2,,线型=& # 39;——& # 39;) plt.xlim ([0.0, 1.0]) plt.ylim ([0.0, 1.05]) plt.xlabel (& # 39; False Positive 率# 39;) plt.ylabel (& # 39; True Positive 率# 39;) plt.title (& # 39; Receiver operating  characteristic 示例# 39;) plt.legend (loc=發ower right") plt.show ()
关于“怎么利用python画出AUC曲线”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看的到。