From 488703bb26a17b1bbbf3dbcf67b82aa1be8e22ee Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Mon, 10 Jun 2019 16:49:17 +0200 Subject: [PATCH] Made f1 score calculation robust against classes with zero predictions Signed-off-by: Jim Martens --- src/twomartens/masterthesis/evaluate.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/twomartens/masterthesis/evaluate.py b/src/twomartens/masterthesis/evaluate.py index 150c3b9..4d1dbca 100644 --- a/src/twomartens/masterthesis/evaluate.py +++ b/src/twomartens/masterthesis/evaluate.py @@ -293,6 +293,9 @@ def get_f1_score(cumulative_precisions: List[np.ndarray], for class_id in range(1, nr_classes + 1): cumulative_precision = cumulative_precisions[class_id] cumulative_recall = cumulative_recalls[class_id] + if (cumulative_precision + cumulative_recall) == 0: + cumulative_f1_scores.append([]) + continue f1_score = 2 * ((cumulative_precision * cumulative_recall) / (cumulative_precision + cumulative_recall)) cumulative_f1_scores.append(f1_score)