# # 导包
# import numpy as np
# import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
from sklearn.svm import SVC
from sklearn.metrics import roc_curve
from sklearn.datasets import make_blobs
from sklearn. model_selection import train_test_split
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
y_test = [1,1,0] 真实标签
几种模型的预测概率
y_score = [0.7,0.8,0.1]
y_score_vgg = [0.6,0.9,0.2]
y_score_google = [0.4,0.7,0.2]
fpr, tpr, thresholds = roc_curve(y_test,y_score)
fpr_vgg , tpr_vgg, thresholds_vgg = roc_curve(y_test,y_score_vgg)
fpr_google, tpr_google, thresholds_google = roc_curve(y_test,y_score_google)
roc_auc = auc(fpr, tpr)
print('resnet_roc:{}'.format(roc_auc))
roc_auc_vgg = auc(fpr_vgg, tpr_vgg)
print('vgg_roc:{}'.format(roc_auc_vgg))
roc_auc_google = auc(fpr_google, tpr_google)
print('google_roc:{}'.format(roc_auc_google))
plt.plot(fpr, tpr, color='darkorange',
lw=2,label='ROC of Resnet(area = 0.9135)')
plt.plot(fpr_vgg, tpr_vgg, color='darkblue',
lw=2,label='ROC of VGG(area = 0.6376)')
plt.plot(fpr_google, tpr_google, color='darkgreen',
lw=2,label='ROC of GooLeNet(area = 0.6613)')
plt.plot([0, 1], [0, 1], color='black', lw=2, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('FPR')
plt.ylabel('TPR')
plt.title('ROC of All Models')
plt.subplots_adjust(wspace=0.6, hspace=0.3)
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.legend(loc='best')
plt.savefig('roc.png')
plt.show()
ROC/AUC
最新推荐文章于 2024-05-21 22:44:12 发布