diff --git a/hiclass/metrics.py b/hiclass/metrics.py index a41f9d92..bddcad55 100644 --- a/hiclass/metrics.py +++ b/hiclass/metrics.py @@ -315,7 +315,7 @@ def _compute_macro( ): overall_sum = 0 for ground_truth, prediction in zip(y_true, y_pred): - if zero_division: + if zero_division is not None: sample_score = _micro_function( np.array([ground_truth]), np.array([prediction]), zero_division ) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 9c7a3e9d..baa9f0aa 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -357,6 +357,7 @@ def test_f1_macro_1d_list_zero_division(): y_true = [1, 2, 3, 4] y_pred = [5, 6, 7, 8] assert 0.0 == f1(y_true, y_pred, "macro") + assert 0.0 == f1(y_true, y_pred, "macro", 0.0) assert 1.0 == f1(y_true, y_pred, "macro", 1.0) assert np.isnan(f1(y_true, y_pred, "macro", np.nan)) @@ -371,6 +372,7 @@ def test_f1_macro_2d_list_zero_division(): y_true = [[1, 2, 3, 4], [5, 6, 7, 8]] y_pred = [[5, 6, 7, 8], [1, 2, 3, 4]] assert 0.0 == f1(y_true, y_pred, "macro") + assert 0.0 == f1(y_true, y_pred, "macro", 0.0) assert 1.0 == f1(y_true, y_pred, "macro", 1.0) assert np.isnan(f1(y_true, y_pred, "macro", np.nan)) @@ -385,6 +387,7 @@ def test_f1_macro_1d_np_array_zero_division(): y_true = np.array([1, 2, 3, 4]) y_pred = np.array([5, 6, 7, 8]) assert 0.0 == f1(y_true, y_pred, "macro") + assert 0.0 == f1(y_true, y_pred, "macro", 0.0) assert 1.0 == f1(y_true, y_pred, "macro", 1.0) assert np.isnan(f1(y_true, y_pred, "macro", np.nan)) @@ -399,6 +402,7 @@ def test_f1_macro_2d_np_array_zero_division(): y_true = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) y_pred = np.array([[5, 6, 7, 8], [1, 2, 3, 4]]) assert 0.0 == f1(y_true, y_pred, "macro") + assert 0.0 == f1(y_true, y_pred, "macro", 0.0) assert 1.0 == f1(y_true, y_pred, "macro", 1.0) assert np.isnan(f1(y_true, y_pred, "macro", np.nan)) @@ -434,6 +438,7 @@ def test_f1_macro_3d_np_array_zero_division(): ] ) assert 0.0 == f1(y_true, y_pred, "macro") + assert 0.0 == f1(y_true, y_pred, "macro", 0.0) assert 1.0 == f1(y_true, y_pred, "macro", 1.0) assert np.isnan(f1(y_true, y_pred, "macro", np.nan))