Skip to content

Instantly share code, notes, and snippets.

@Keiku
Last active October 5, 2022 01:52
Show Gist options
  • Save Keiku/b6dca88b9bbe7b55701e43f7f5ee19a6 to your computer and use it in GitHub Desktop.
Save Keiku/b6dca88b9bbe7b55701e43f7f5ee19a6 to your computer and use it in GitHub Desktop.
Plot ROC curve.
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
import seaborn as sns
sns.set('talk', 'whitegrid', 'dark', font_scale=1.5, font='Ricty',
rc={"lines.linewidth": 2, 'grid.linestyle': '--'})
fpr, tpr, _ = roc_curve([1, 0, 1, 0, 1, 0, 0], [0.9, 0.8, 0.7, 0.7, 0.6, 0.5, 0.4])
roc_auc = auc(fpr, tpr)
lw = 2
plt.figure()
plt.plot(fpr, tpr, color='darkorange',
lw=lw, label='ROC curve (AUC = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('偽陽性率(False Positive Rate)')
plt.ylabel('真陽性率(True Positive Rate)')
plt.title('ROC曲線(Receiver Operating Characteristic curve)')
plt.legend(loc="lower right")
plt.show()
plt.savefig('roc_auc.png')
plt.close()
@shaunildm
Copy link

Would anyone like to see a seaborn-only alternative?

yes, that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment