Skip to content

Instantly share code, notes, and snippets.

@bryanyang0528
Last active August 29, 2015 14:23
Show Gist options
  • Save bryanyang0528/72ed4ddf07c54af109b9 to your computer and use it in GitHub Desktop.
Save bryanyang0528/72ed4ddf07c54af109b9 to your computer and use it in GitHub Desktop.
import numpy as np
def roc(actual, pred):
fpr=np.array([1.0])
tpr=np.array([1.0])
n=float(len(actual)-sum(actual))
p=float(sum(actual))
for i in np.arange(min(pred), max(pred), 1.0/len(pred)):
TP=0.0
FP=0.0
for j in range(len(pred)):
if (pred[j] > i) & (actual[j]==1):
TP+=1
if (pred[j] > i) & (actual[j]==0):
FP+=1
tpr = np.insert(tpr, 0, TP/p)
fpr = np.insert(fpr, 0, FP/n)
return fpr, tpr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment