Skip to content

Instantly share code, notes, and snippets.

@ankane
Created December 11, 2011 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ankane/1461732 to your computer and use it in GitHub Desktop.
Save ankane/1461732 to your computer and use it in GitHub Desktop.
Calculates F1 score
# http://en.wikipedia.org/wiki/F1_score
# true positives, false positives, false negatives
def f1_score(tp, fp, fn)
precision = tp / (tp + fp).to_f
recall = tp / (tp + fn).to_f
2.0 * precision * recall / (precision + recall)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment