我有两个函数,给出精度和召回分数,我需要做一个调和平均函数,定义在同一个库中,使用这两个分数。函数如下所示:
功能如下:
def precision(ref, hyp):
"""Calculates precision.
Args:
- ref: a list of 0's and 1's extracted from a reference file
- hyp: a list of 0's and 1's extracted from a hypothesis file
Returns:
- A floating point number indicating the precision of the hypothesis
"""
(n, np, ntp) = (len(ref), 0.0, 0.0)
for i in range(n):
if bool(hyp[i]):
np += 1
if bool(ref[i]):
ntp += 1
return ntp/np
def recall(ref, hyp):
"""Calculates recall.
Args:
- ref: a list of 0's and 1's extracted from a reference file
- hyp: a list of 0's and 1's extracted from a hypothesis file
Returns:
- A floating point number indicating the recall rate of the hypothesis
"""
(n, nt, ntp) = (len(ref), 0.0, 0.0)
for i in range(n):
if bool(ref[i]):
nt += 1
if bool(hyp[i]):
ntp += 1
return ntp/nt
调和平均函数是什么样子? 我只有这个,但我知道这是不对的:
^{pr2}$
以下参数适用于任意数量的参数:
要计算}的调和平均值,请使用:
^{pr2}$precision
和{您的功能有两个问题:
只需稍微修改一下您的}函数,我可以这样做:
F1
函数,并使用您定义的相同的precision
和{特别是复习我所掌握的变量的用法。必须计算每个函数的结果并将其传递给
F1
函数。在相关问题 更多 >
编程相关推荐