def calc_f1_score(predictions,labels):
predictions = np.argmax(predictions,1)
labels = np.argmax(labels,1)
tp = fp = tn = fn = 0
for a,b in zip(predictions,labels):
if a == 1:
if a == b:
tp += 1
else:
fp += 1
else:
if a == b:
tn += 1
else:
fn += 1
precision = ( tp / (tp + fp) ) if (tp + fp) > 0 else 0
recall = ( tp / (tp + fn) ) if (tp + fn) > 0 else 0
f1_score = 2*((precision * recall) / (precision + recall )) if (precision + recall) > 0 else 0
return f1_score
#Argument handling, Copy paste from tflearn_rnn.py
评论列表
文章目录