|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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 = [0,1,1,0,1,0]
Prec_case = [0,0,1,1,0.0]
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已经空了
|
|