pop()列表时为空
def get_F1_score(true_case,prec_case):TP=0
FN=0
TN=0
FP=0
for i in range(len(true_case)):
t = true_case.pop()
p = prec_case.pop()
if t==1 and p==1:
TP += 1
elif t==1 and p==0:
FN += 1
elif t==0 and p==1:
FP += 1
else:
TN += 1
Precision = TP/(TP+FP)
Recall = TP/(TP+FN)
F1_score = 2*TP/(2*TP+FN+FP)
print("TP=%d,FN=%d,FP=%d,TN=%d"%(TP,FN,FP,TN))
return F1_score
True_case =
Prec_case =
F1_score = get_F1_score(True_case,Prec_case)
print("F1_score= " + str(F1_score))
运行时显示p = prec_case.pop()这一行代码pop from empty list,不明白为什么为空?当我把 for i in range(len(true_case)):中的true_case换成prec_case又能够正常运行,求解答! 因为true_case比prec_case长,所以循环还在继续时,prec_case已经空了
他俩不是相等的吗 qiuyouzhi 发表于 2020-3-20 10:52
因为true_case比prec_case长,所以循环还在继续时,prec_case已经空了
他俩长度不是相等的吗? xiao_lei 发表于 2020-3-20 11:20
他俩长度不是相等的吗?
prec_case:
0,0,1,1,0.0
你写成小数点了
页:
[1]