大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
项目中需要判断用户提交的多选题选项的正确率,比如正确答案应该为a, b, c,而用户选择的是a, d,那么如何判断他的正确率呢,这个场景就需要用到F1 score来计算。
From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/F1_score
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)
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/181883.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...