From e7547de9febe969cde7c64f20ebaa0ca5f4673b6 Mon Sep 17 00:00:00 2001 From: Uri Alon Date: Wed, 2 Feb 2022 14:33:34 -0500 Subject: [PATCH] F1 calculation return 0 if precision and recall are zero --- tensorflow_model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tensorflow_model.py b/tensorflow_model.py index 8c9229f..6cbdac4 100644 --- a/tensorflow_model.py +++ b/tensorflow_model.py @@ -490,7 +490,10 @@ def recall(self): @property def f1(self): - return 2 * self.precision * self.recall / (self.precision + self.recall) + if self.precision + self.recall == 0: + return 0 + else: + return 2 * self.precision * self.recall / (self.precision + self.recall) class TopKAccuracyEvaluationMetric: