Skip to content

Instantly share code, notes, and snippets.

@nsorros
Created February 14, 2022 12:27
Show Gist options
  • Save nsorros/2e4185d4bcd9a323e1299bf2bb625532 to your computer and use it in GitHub Desktop.
Save nsorros/2e4185d4bcd9a323e1299bf2bb625532 to your computer and use it in GitHub Desktop.
updated = False
for k in range(N):
start = time.time()
y_pred_proba = np.array(Y_pred_proba[:,k].todense()).ravel()
y_test = np.array(Y_test[:,k].todense()).ravel()
fp = partial(f, y_pred_proba, y_test, mlcm, k)
optimal_thresholds_star = argmaxf1(y_pred_proba, y_test, optimal_thresholds, mlcm, k, nb_thresholds)
if fp(optimal_thresholds_star) > fp(optimal_thresholds):
optimal_thresholds = optimal_thresholds_star
Y_pred = Y_pred_proba > optimal_thresholds
mlcm = multilabel_confusion_matrix(Y_test, Y_pred)
updated = True
print(f"label {k} - updated {updated} - time elapsed {time.time()-start:.2f}s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment