Created
March 25, 2013 02:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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