Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # Listing 3
  2. def roc_curve(y, prob):
  3. tpr_list = []
  4. fpr_list = []
  5. threshold = np.linspace(1.1, 0, 10)
  6. for t in threshold:
  7. y_pred = np.zeros(y.shape[0])
  8. y_pred[prob >= t] = 1
  9. TN = y_pred[(y_pred == y) & (y == 0)].shape[0]
  10. TP = y_pred[(y_pred == y) & (y == 1)].shape[0]
  11. FP = y_pred[(y_pred != y) & (y == 0)].shape[0]
  12. FN = y_pred[(y_pred != y) & (y == 1)].shape[0]
  13. TPR = TP / (TP + FN)
  14. FPR = FP / (FP + TN)
  15. tpr_list.append(TPR)
  16. fpr_list.append(FPR)
  17. return fpr_list, tpr_list, threshold
  18.  
  19. prob = predict_proba(x)
  20. fpr, tpr, threshold = roc_curve(y, prob)
  21.  
  22. plt.plot(fpr, tpr, 'b')
  23. plt.plot([0,1],[0,1], 'r--')
  24. plt.xlabel("False Positive Rate", fontsize=12)
  25. plt.ylabel("True Positive Rate", fontsize=12)
  26.  
  27. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement