python 画 ROC 曲线

python  画 ROC 曲线的实现代码

import numpy as np
import matplotlib.pyplot as plt

from sklearn.metrics import auc  ###计算roc和auc
import pandas as pd

base = "D:\\WFLW\\wflw_blur_128\\ROC\\"

df =pd.read_csv( base + "sobel_roc.txt", encoding='utf8', delimiter=' ', header=0)
df_lap =pd.read_csv( base + "lap_roc.txt", encoding='utf8', delimiter=' ', header=0)
df_dft =pd.read_csv( base + "dft_roc.txt", encoding='utf8', delimiter=' ', header=0)
df_cnn =pd.read_csv( base + "cnn_roc.txt", encoding='utf8', delimiter=' ', header=0)

tpr = df['tpr']
fpr = df['fpr']

tpr_lap = df_lap['tpr']
fpr_lap = df_lap['fpr']

tpr_dft = df_dft['tpr']
fpr_dft = df_dft['fpr']

tpr_cnn = df_cnn['tpr']
fpr_cnn = df_cnn['fpr']

roc_auc = auc(fpr, tpr) ###计算auc的值

roc_auc_lap = auc(fpr_lap, tpr_lap) ###计算auc的值

roc_auc_dft = auc(fpr_dft, tpr_dft) ###计算auc的值

roc_auc_cnn = auc(fpr_cnn, tpr_cnn)

print(roc_auc)

plt.figure()
lw = 2
plt.figure(figsize=(10,10))
plt.plot(fpr, tpr, color='darkorange', lw=lw, label='Sobel ROC curve (area = %0.2f)' % roc_auc) ###假正率为横坐标,真正率为纵坐标做曲线

plt.plot(fpr_lap, tpr_lap, color='navy', lw=lw, label='Lap ROC curve (area = %0.2f)' % roc_auc_lap)

plt.plot(fpr_dft, tpr_dft, color='red', lw=lw, label='Dft ROC curve (area = %0.2f)' % roc_auc_dft)

plt.plot(fpr_cnn, tpr_cnn, color='green', lw=lw, label='CNN ROC curve (area = %0.2f)' % roc_auc_cnn)
#plt.plot(tpr, fpr, 'k--', label='Mean ROC (area = %0.2f)' % 1, lw=2)

#plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')

plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.savefig(base + "roc_img\\sobel_roc.jpg")
plt.show()

画图结果

python 画 ROC 曲线_第1张图片

你可能感兴趣的:(python,机器学习,深度学习)