python画ROC曲线

穿精又带淫゛_ 提交于 2020-01-08 10:50:30
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")

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!