Skip to content

Fix McNemar ZeroDivisionError when models have no discordant pairs - #795

Open
tonycoder-hub wants to merge 1 commit into
huggingface:mainfrom
tonycoder-hub:cursor/fix-mcnemar-zero-division-39bb
Open

Fix McNemar ZeroDivisionError when models have no discordant pairs#795
tonycoder-hub wants to merge 1 commit into
huggingface:mainfrom
tonycoder-hub:cursor/fix-mcnemar-zero-division-39bb

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Description

McNemar's statistic is |b - c|² / (b + c). When the two models being compared produce no discordant pairs (b + c == 0) — comparing a model to itself, or two models that agree on every example — this raised ZeroDivisionError.

The comparison now reports stat = 0.0 in that case, which yields p = 1.0: there is no evidence of a difference.

Tests

python3 -m pytest tests/test_metric_common.py -k "comparison or mcnemar" -q → 4 passed, 3 skipped.

New test_mcnemar_without_discordant_pairs fails on unmodified source.

McNemar's statistic divides by the number of discordant pairs, so comparing
two models that are correct and incorrect on exactly the same examples raised
a ZeroDivisionError. Report a statistic of 0.0 (and therefore a p value of
1.0) instead, since there is no evidence of a difference in that case.

Co-authored-by: Tony Coder <407243179@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants