I draw the ROC curve for different classifiers with the following code, but in all plots (from different classifiers), the diagrams are triangular like the example below. How can I have a smoother plot?
def plot_roc_curve(fpr, tpr, classifier):
plt.plot(fpr, tpr, color='orange', label='ROC')
plt.plot([0, 1], [0, 1], color='darkblue', linestyle='--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title(str(classifier) + 'Receiver Operating Characteristic (ROC) Curve ')
plt.legend(loc="lower right")
plt.show()
from sklearn.metrics import roc_curve
fpr, tpr, thresholds = roc_curve(y_test, y_predicted)
plot_roc_curve(fpr, tpr, key)
The dataset: https://www.file.io/download/Aq7LT88NBVSh
y_test
36 1
988 0
416 1
300 1
860 0
..
780 0
130 1
316 1
577 0
694 0
y_predict
[1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0
1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 0 1 0 0 1 1 0
1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1 0 0 1 1 1 0 0 1 0 1 0 1 1 0 1 0 1 1 0 1 1
1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 1
1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 0 1
1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1
1 1 1]
You're using thresholded predictions to generate the ROC-curve. You should instead use the original confidence values, otherwise you will get only 1 intermediary point on the curve.
Here is some example data and the ROC-curves you would get.
y_test: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, ...
y_predicted: [1, 0.405, 0.601, 0.579, 0.03, 0.98, 0.06, 0.242, 0.379, 0.09, ...
y_predicted_thresholded: [1, 0, 1, 1, 0, 1, 0, 0, 0, 0, ...
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.