Skip to content

Instantly share code, notes, and snippets.

@kusal1990
Created June 2, 2022 18:38
Show Gist options
  • Save kusal1990/b6ccddd1fb15727440ea87cad55b6c12 to your computer and use it in GitHub Desktop.
Save kusal1990/b6ccddd1fb15727440ea87cad55b6c12 to your computer and use it in GitHub Desktop.
def threshold_search(y_true, y_proba):
best_threshold = 0
best_score = 0
for threshold in tqdm([i * 0.01 for i in range(100)]):
score = K.eval(matthews_correlation(y_true.astype(np.float64), (y_proba > threshold).astype(np.float64)))
if score > best_score:
best_threshold = threshold
best_score = score
search_result = {'threshold': best_threshold, 'matthews_correlation': best_score}
return search_result
@kusal1990
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment