Python - ROC Curve
ROC Curve Plotter
Import modules
- Using
sklearnto plot the ROC Curve1
2
3import numpy as np
from sklearn.metrics import accuracy_score, confusion_matrix, roc_auc_score, roc_curve
import matplotlib.pyplot as plt
- Using
Plot curve
- get the false positive rate, true positive rate and thresholds by inputting the passing coordinates.
1
2
3
4
5
6
7
8
9
10
11
12# Get the require elements
fpr, tpr, thresholds = roc_curve([0,1,0,1,0,1], [0.56, 0.61, 0.43, 0.78, 0.12, 0.47])
# sketch the coordinates
plt.scatter([0, 0, 1/3, 1/3, 2/3, 2/3, 0, 1], [1/3, 2/3, 2/3, 1, 1, 1, 0, 1])
# plot the curve
plt.plot(fpr, tpr)
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
print(f'model 1 AUC score: {roc_auc_score([0,1,0,1,0,1], [0.56, 0.61, 0.43, 0.78, 0.12, 0.47])}')
- get the false positive rate, true positive rate and thresholds by inputting the passing coordinates.
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.


