﻿ F1 score | 阿小信的博客

阿小信的博客 Life is short (You need Python) Bruce Eckel

F1 score2014-09-03 03:22

In statistical analysis of Binary classification, the F1 score (also F-score or F-measure) is a measure of a test's accuracy.

It considers both the precision p and the recall r of the test to compute the score:

p is the number of correct results divided by the number of all returned results and r is the number of correct results divided by the number of results that should have been returned.

The F1 score can be interpreted as a weighted average of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0.

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #!/usr/bin/env python #-*- coding:utf-8 -*- def get_f1(standard_answer, user_answer): s_user_answer = set(user_answer) s_standard_answer = set(standard_answer) correct_results_len = len(s_user_answer & s_standard_answer) precision = (correct_results_len + 1e-8) / (len(user_answer) + 1e-8) recall = (correct_results_len + 1e-8) / (len(standard_answer) + 1e-8) f1 = 2 * precision * recall / (precision + recall) return f1 if __name__ == '__main__': standard = ['a', 'c', 'd'] user = ['a'] print get_f1(standard, user)

#Python#   阅读 评论