Skip to content
Eval Suites50

McNemar’s test example for a paired LLM release evaluation

Sources checked 2 min read · By the Eval Suites editors

In brief

Use McNemar’s test when two versions receive the same cases and each result is a pass or fail. Count both directions of change and read the regressions by case ID. Two evaluations can show the same gain in pass rate and give different evidence about its reliability.

Match each baseline result to its candidate result

Run both versions on the same labeled snapshot and join the results by case ID. Before you count outcomes, check that each version has one usable result per case and investigate timeouts or missing rows. If timeouts count as failure for the user-facing behavior, decide that rule before inspecting results. McNemar’s test takes a 2 × 2 table of paired outcomes.[1]

Consider two fictional release trials for the Harbor Library help desk. Each has 100 independent cases and an increase from 68% to 76%. Trial A fixes eight failures. Trial B fixes eighteen and introduces ten new ones. The two headline gains conceal different patterns.

Two illustrative paired trial results with the same eight-point gain
Outcome on the same caseTrial ATrial B
Passes on both versions6858
Passes baseline only010
Passes candidate only818
Fails on both versions2414

Use the discordant pairs in the exact test

Under the null hypothesis of equal marginal pass probabilities, a discordant pair is equally likely to favor either version. The exact two-sided test takes the two changed counts as the evidence. In statsmodels, mcnemar(table, exact=True) uses the binomial distribution. Leave the unchanged counts in the report so readers can recover the denominator for both pass rates.[1]

Reproduce the two exact two-sided p-values with Python
from math import comb

def exact_mcnemar(regressions, improvements):
    changed = regressions + improvements
    tail = sum(
        comb(changed, count)
        for count in range(min(regressions, improvements) + 1)
    )
    return min(1.0, 2 * tail / (2 ** changed))

for trial, losses, wins in [("A", 0, 8), ("B", 10, 18)]:
    print(trial, f"{exact_mcnemar(losses, wins):.5f}")

The example prints A 0.00781 and B 0.18493. With a prespecified 5% significance level, A provides evidence against equal marginal pass rates. B leaves that question unresolved. Report the observed gain of eight percentage points for each and the counts supporting it. A p-value answers the test’s equality question. Set a separate requirement for the smallest gain worth shipping.

Read the cases that changed before approving a release

Open the ten regressions in Trial B. Suppose one answer sends a visitor to a branch on its closed day. A rule that every closure case must pass still blocks the release. Save the failed case IDs, the aggregate gain, the changed counts, the test and its result in the release record.

Repeated runs from one conversation family or multiple paraphrases of one schedule question can yield dependent outcomes. The example’s exact p-values assume independent pairs. Preserve the case-family identifier and use an analysis that accounts for clustering when the evaluation design creates related cases. For graded scores, keep the original scores and compare paired differences unless the product decision already defines a meaningful pass boundary.[2]

Set release gates for failures and latency that require separate checks

Related suites

    Related reading

    Sources

    1. 1. McNemar’s test in statsmodels · statsmodels · Official docs · Sources checked
    2. 2. Adding Error Bars to Evals: A Statistical Approach to Language Model Evaluations · Evan Miller, arXiv:2411.00640 · Paper · Sources checked