0
votes

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 :

enter image description here

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

1
Add your results for 1st code as wellIrfan Umar
I added the printed value of each variableRSR

1 Answers

0
votes

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.