Last active
October 15, 2020 20:37
-
-
Save esmitt/28cf2c9ebc58de570d62830af51b6a25 to your computer and use it in GitHub Desktop.
Plotting the ROC curve using matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import roc_auc_score, roc_curve | |
def plot_roc(name: str, labels: numpy.ndarray, predictions: numpy.ndarray, **kwargs) -> (): | |
fp, tp, _ = roc_curve(labels, predictions) | |
auc_roc = roc_auc_score(labels, predictions) | |
plt.plot(100*fp, 100*tp, label=name + " (" + str(round(auc_roc, 3)) + ")", | |
linewidth=2, **kwargs) | |
plt.xlabel('False positives [%]') | |
plt.ylabel('True positives [%]') | |
plt.title('ROC curve') | |
plt.grid(True) | |
plt.legend(loc='best') | |
ax = plt.gca() | |
ax.set_aspect('equal') | |
plot_roc("Train Base", y_train, y_train_pred, color=colors[0]) | |
plot_roc("Test Base", y_test, y_test_pred, color=colors[0], linestyle='--') | |
plt.legend(loc='lower right') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment