Skip to content

Instantly share code, notes, and snippets.

@agarie
Created March 25, 2013 02:31
Show Gist options
  • Save agarie/5234570 to your computer and use it in GitHub Desktop.
Save agarie/5234570 to your computer and use it in GitHub Desktop.
F1 score in Ruby. I use this snippet a lot, but usually rewrite it for each project... not anymore.
# The F1 score is a measure of how accurate an algorithm is.
#
# Precision is the probability that a (randomly selected) retrieved document is relevant:
# precision = true positives / (true positives + false positives)
#
# Recall is the probability that a (randomly selected) relevant document is retrieved in a search:
# recall = true positives / (true positives + false negatives)
def f1_score(precision, recall)
(2 * (precision * recall)) / (precision + recall)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment