Skip to content

Instantly share code, notes, and snippets.

@arthurdouillard
Last active April 9, 2019 16:30
Show Gist options
  • Save arthurdouillard/c26c51da91e1010fab3528211cee6a4c to your computer and use it in GitHub Desktop.
Save arthurdouillard/c26c51da91e1010fab3528211cee6a4c to your computer and use it in GitHub Desktop.
def compute_metrics(true_pos, false_pos, false_neg):
"""Compute the precision, recall, and f1 score."""
precision = true_pos / (true_pos + false_pos)
recall = true_pos / (true_pos + false_neg)
if precision == 0 or recall == 0:
return precision, recall, 0
f1 = 2 / (1 / precision + 1 / recall)
return precision, recall, f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment