Fix macro average calculation in geometric_mean_score for binary classification#1164
Fix macro average calculation in geometric_mean_score for binary classification#1164shubhrai23 wants to merge 2 commits into
Conversation
|
Thanks for tackling #1096 — the diagnosis (binary macro returning The bug isn't binary-specific — multiclass macro is wrong too. This PR only switches to the per-class computation when y_true = [0, 1, 2, 0, 1, 2]; y_pred = [0, 2, 1, 0, 1, 2]
geometric_mean_score(y_true, y_pred, average=None) # [1. , 0.612, 0.612]
np.mean(...) # 0.7416 <- expected
geometric_mean_score(y_true, y_pred, average="macro") # 0.7454 <- still wrong with this PRI verified this by checking out the branch locally — after the patch, Related concern: the existing parametrized tests ( The root cause is the same for binary and multiclass ( Either way, removing the special-casing and fixing the multiclass expected values would make this complete. |
Geometric_mean_score with average='macro' was incorrect for binary classification (it was calculating the arithmetic mean of scores instead of the geometric mean of sensitivity and specificity).
Added a check to handle binary cases correctly while preserving multiclass behavior.
Added a regression test.