python画ROC曲线

import numpy as np
from sklearn import metrics 
from matplotlib import pyplot

path = "PFS3_val_result.csv"
with open(path, 'r') as f:
    file_list = f.read()
    file_list = file_list.split('\n')[1:-1]
    file_list = [file.split(',') for file in file_list]                     

y = np.array([float(y[1]) for y in file_list])
scores1 = np.array([float(preds[2]) for preds in file_list])
scores2 = np.array([float(preds[3]) for preds in file_list])
scores3 = np.array([float(preds[4]) for preds in file_list])

fpr1, tpr1, thresholds1 = metrics.roc_curve(y, scores1, pos_label=1)
fpr2, tpr2, thresholds2 = metrics.roc_curve(y, scores2, pos_label=1)
fpr3, tpr3, thresholds3 = metrics.roc_curve(y, scores3, pos_label=1)

#print("fpr:{},tpr:{},thresholds:{}".format(fpr,tpr,thresholds))
roc_auc1 = metrics.auc(fpr1, tpr1)
roc_auc2 = metrics.auc(fpr2, tpr2)
roc_auc3 = metrics.auc(fpr3, tpr3)

print(roc_auc1,roc_auc2,roc_auc3)

pyplot.plot(fpr1, tpr1, lw=1, color='green', label="Deep Learning, AUC=%0.3f" % (roc_auc1))
pyplot.plot(fpr2, tpr2, lw=1, color='blue', label="Radiomics, AUC=%0.3f" % (roc_auc2))
pyplot.plot(fpr3, tpr3, lw=1, color='red', label="Deep Learning+Radiomics, AUC=%0.3f" % (roc_auc3))
    
pyplot.xlim([0.00, 1.0])
pyplot.ylim([0.00, 1.0])
pyplot.xlabel("False Positive Rate")
pyplot.ylabel("True Positive Rate")
pyplot.title("PFS3_VAL_ROC")
pyplot.legend(loc="lower right")
pyplot.savefig(r"./PFS3_VAL_ROC.png")

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值