Skip to content

Instantly share code, notes, and snippets.

@wadeschulz
Created December 10, 2017 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wadeschulz/96566f64e005caa8e75e2b80807e0887 to your computer and use it in GitHub Desktop.
Save wadeschulz/96566f64e005caa8e75e2b80807e0887 to your computer and use it in GitHub Desktop.
Create ROC curve from ML scores in numpy array
from sklearn import metrics
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def create_roc_curve(labels, scores, positive_label)
fpr, tpr, thresholds = metrics.roc_curve(labels, scores, pos_label=positive_label)
roc_auc = auc(fpr, tpr)
plt.title('Receiver Operating Characteristic')
plt.plot(fpr, tpr, 'b', label='AUC = %0.2f'% roc_auc)
plt.legend(loc='lower right')
plt.plot([0,1],[0,1],'r--')
plt.xlim([-0.1,1.2])
plt.ylim([-0.1,1.2])
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.show()
y = np.array([0, 0, 1, 1])
scores = np.array([0.1, 0.4, 0.35, 0.8])
create_roc_curve(y, scores, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment