Skip to content

Instantly share code, notes, and snippets.

@nsorros
Last active February 14, 2022 12:32
Show Gist options
  • Save nsorros/12681d3d50f0853a22c7ca8f4cf05b68 to your computer and use it in GitHub Desktop.
Save nsorros/12681d3d50f0853a22c7ca8f4cf05b68 to your computer and use it in GitHub Desktop.
def multilabel_confusion_matrix(Y_test, Y_pred):
tp = Y_test.multiply(Y_pred).sum(axis=0)
fp = Y_pred.sum(axis=0) - tp
fn = Y_test.sum(axis=0) - tp
tn = Y_test.shape[0] - tp - fp - fn
return np.array([tn, fp, fn, tp]).T.reshape(-1, 2, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment