Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def find_thresh(y_true, y_pred):
  2. y_pred, y_true = zip(*sorted(zip(y_pred, y_true)))
  3.  
  4. TP = np.sum(y_true)
  5. FP = len(y_true) - TP
  6. FN = 0
  7.  
  8. best_thresh = y_pred[0]
  9. best_score = 2 * TP / (2 * TP + FP + FN)
  10.  
  11. for i in range(1, len(y_pred)):
  12. cur_thresh = y_pred[i]
  13. if y_true[i]:
  14. TP -= 1
  15. FN += 1
  16. else:
  17. FP -= 1
  18.  
  19. cur_score = 2 * TP / (2 * TP + FP + FN)
  20. if cur_score > best_score:
  21. best_thresh = cur_thresh
  22. best_score = cur_score
  23.  
  24. return best_thresh, best_score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement