python设计一个函数定义计算并返回n价调和函数_python函数的调和平均值?

我有两个函数,给出精度和召回分数,我需要做一个调和平均函数,定义在同一个库中,使用这两个分数。函数如下所示:

功能如下: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}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值