ROC/AUC

该代码段展示了如何计算并绘制Resnet、VGG和GoogleNet模型在二分类任务上的ROC曲线,以及对应的AUC值。通过ROC曲线和AUC,可以评估这三个模型的性能。Resnet的AUC为0.9135,VGG的AUC为0.6376,GoogleNet的AUC为0.6613。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# # 导包
# 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()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值