Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Listing 3
- def roc_curve(y, prob):
- tpr_list = []
- fpr_list = []
- threshold = np.linspace(1.1, 0, 10)
- for t in threshold:
- y_pred = np.zeros(y.shape[0])
- y_pred[prob >= t] = 1
- TN = y_pred[(y_pred == y) & (y == 0)].shape[0]
- TP = y_pred[(y_pred == y) & (y == 1)].shape[0]
- FP = y_pred[(y_pred != y) & (y == 0)].shape[0]
- FN = y_pred[(y_pred != y) & (y == 1)].shape[0]
- TPR = TP / (TP + FN)
- FPR = FP / (FP + TN)
- tpr_list.append(TPR)
- fpr_list.append(FPR)
- return fpr_list, tpr_list, threshold
- prob = predict_proba(x)
- fpr, tpr, threshold = roc_curve(y, prob)
- plt.plot(fpr, tpr, 'b')
- plt.plot([0,1],[0,1], 'r--')
- plt.xlabel("False Positive Rate", fontsize=12)
- plt.ylabel("True Positive Rate", fontsize=12)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement