简体   繁体   中英

Plot ROC curve using sklearn

I tried to create an ROC curve with sklearn, below is my code

from sklearn.metrics import roc_curve
fpr_keras, tpr_keras, thresholds_keras = roc_curve(validation_generator.classes, y_pred_label_indices)

when I print

print(fpr_keras):

[0.    0.48  0.568 0.584 0.632 0.648 0.664 0.68  0.992 0.992 1.    1.   ]

print(tpr_keras)

[0.    0.    0.    0.    0.    0.    0.    0.    0.    0.016 0.016 1.   ]

print(thresholds_keras)

[2.0000000e+00 1.0000000e+00 9.9999988e-01 9.9999976e-01 9.9999893e-01
 9.9999881e-01 9.9999833e-01 9.9999821e-01 9.6940529e-01 6.8794215e-01
 5.7934558e-01 1.9927023e-05]

but when I plotted it using this code:

plt.plot(fpr_keras, tpr_keras, thresholds_keras)
plt.plot([0,1], [0,1], 'r--')
plt.xlim([0, 1])
plt.ylim([0, 1])

I got this:

在此处输入图像描述

why is that?, is there something wrong with my code?

ROC curve is a plot of fpr and tpr only. for ploting ROC curve you should just do this plt.plot(fpr,tpr)

However, with the data you provided, results are very bad for ROC curve.

Now, the plot that you have shown above is the result of

plt.plot([0,1], [0,1], 'r--') plt.xlim([0, 1]) plt.ylim([0, 1]) only not an ROC curve

Try running both codes separately. You 'll get it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM