Skip to content

McNemar: exact test for few disagreements, and no crash when there are none - #914

Open
WatchTree-19 wants to merge 1 commit into
huggingface:mainfrom
WatchTree-19:fix/mcnemar-exact
Open

WatchTree-19 wants to merge 1 commit into
huggingface:mainfrom
WatchTree-19:fix/mcnemar-exact

Conversation

@WatchTree-19

Copy link
Copy Markdown

The McNemar comparison always used the chi-square approximation, which is unreliable when the two models disagree on few examples. In the module's own example they disagree on one example: it reported p = 0.317, and the exact binomial test gives p = 1.0. When the models never disagree, b + c = 0 and the statistic raised ZeroDivisionError.

  • With fewer than 25 discordant pairs, p now comes from the exact binomial test on those pairs. Above that the chi-square test is unchanged.
  • With no discordant pairs the comparison returns stat 0 and p 1.
  • p is returned as a plain float, so the docstring example also passes on numpy 2.
Before After
Module example (1 disagreement) p = 0.317 p = 1.0
No disagreements ZeroDivisionError stat 0, p 1

Tests: 3 new in tests/test_mcnemar.py, all fail on main. README updated.

…e none

The comparison always used the chi-square approximation, which is
unreliable when the two models disagree on few examples. In the module's
own example they disagree on one example, and it reported p = 0.317; the
exact binomial test gives p = 1.0. When the models never disagree,
b + c = 0 and the statistic raised ZeroDivisionError.

With fewer than 25 discordant pairs, p now comes from the exact binomial
test on those pairs; above that the chi-square test is unchanged. With no
discordant pairs the comparison returns stat 0 and p 1. p is returned as
a plain float, so the docstring example also passes on numpy 2.
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.

1 participant