Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hiclass/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand Down Expand Up @@ -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))

Expand Down