Skip to content

Instantly share code, notes, and snippets.

@joao-timescale
Created November 26, 2017 12:41
Show Gist options
  • Save joao-timescale/57f3f63be05f8db279059e505cf4d898 to your computer and use it in GitHub Desktop.
Save joao-timescale/57f3f63be05f8db279059e505cf4d898 to your computer and use it in GitHub Desktop.
k-NN metrics
hits = np.asarray([cnf_matrix[i][i] for i in range(cnf_matrix.shape[0])])
expected = np.sum(cnf_matrix, axis=0)
num_hits = np.sum(hits)
total = test_data.shape[0]
precision = 100 * (num_hits / total)
recall_per_class = hits / expected
recall = 100 * (np.sum(recall_per_class) / recall_per_class.shape[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment