Fix f-score calculation if zero

This commit is contained in:
Matthew Honnibal 2019-02-23 12:45:41 +01:00
parent 6b0008afc6
commit 981cb89194
1 changed files with 4 additions and 1 deletions

View File

@ -140,6 +140,9 @@ def evaluate(tokenizer, textcat, texts, cats):
fn += 1
precision = tp / (tp + fp)
recall = tp / (tp + fn)
if (precision+recall) == 0:
f_score = 0.0
else:
f_score = 2 * (precision * recall) / (precision + recall)
return {"textcat_p": precision, "textcat_r": recall, "textcat_f": f_score}