Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_thresh(y_true, y_pred):
- y_pred, y_true = zip(*sorted(zip(y_pred, y_true)))
- TP = np.sum(y_true)
- FP = len(y_true) - TP
- FN = 0
- best_thresh = y_pred[0]
- best_score = 2 * TP / (2 * TP + FP + FN)
- for i in range(1, len(y_pred)):
- cur_thresh = y_pred[i]
- if y_true[i]:
- TP -= 1
- FN += 1
- else:
- FP -= 1
- cur_score = 2 * TP / (2 * TP + FP + FN)
- if cur_score > best_score:
- best_thresh = cur_thresh
- best_score = cur_score
- return best_thresh, best_score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement