当前位置:   article > 正文

python 电压 谐波_python函数中的谐波表示?

python中harmonic函数

I have 2 functions that give out precision and recall scores, I need to make a harmonic mean function defined in the same library that uses these two scores. The functions looks like this:

here are the functions:

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

What would the harmonic mean function look like?

All I have is this but I know its not right:

def F1(precision, recall):

(2*precision*recall)/(precision+recall)

解决方案

With a slight change of your F1 function, and with the same precision and recall function you defined, I have this working:

def F1(precision, recall):

return (2*precision*recall)/(precision+recall)

r = [0,1,0,0,0,1,1,0,1]

h = [0,1,1,1,0,0,1,0,1]

p = precision(r, h)

rec = recall(r, h)

f = F1(p, rec)

print f

Review especially the use of variables I have. You must compute the result of each function and pass them to the F1 function.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/261466
推荐阅读
相关标签
  

闽ICP备14008679号