Two classifiers A and B are evaluated on the same 1,000 test examples. A is right and B wrong on 30 examples; B is right and A wrong on 15. Is A significantly better at the 5% level, and what does the p-value mean here?
Probability and statistics, Hypothesis testing
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can choose a paired test for classifiers scored on the same test set, compute it, and interpret a p-value correctly.
Key idea
Only the examples where the models disagree tell you which is better. Under the null hypothesis (equal error rates), each disagreement is equally likely to favour A or B. McNemar's statistic then approximately follows a chi-squared distribution with 1 degree of freedom ().
Steps
- Build the 2×2 table of (A right or wrong) against (B right or wrong). The two disagreement counts are (A right, B wrong) and (B right, A wrong). Ignore the examples where they agree.
- State : a disagreement is equally likely to go either way, so .
- Compute: . The 5% critical value of is 3.84, and , so reject ; . The “” is a continuity correction for using a smooth distribution on counts. Without it, and . The exact two-sided binomial test gives .
- Interpret the p-value. It is the probability, if were true, of seeing a split of disagreements at least this lopsided. It is not the probability that is true, nor the probability that A is better.
- Explain why the test must be paired. Both accuracies come from the same examples, so they are correlated, and a test that treats them as independent is wrong. When comparing models across CV folds, the usual paired t-test underestimates the variance because the training sets overlap; use the 5×2 cv test or the corrected resampled t-test. If you test many models, correct for multiple comparisons.
Common mistakes
- Including the examples where both models agree. They say nothing about which model is better.
- Saying “ means a 3.7% chance that A is not better”.
- Treating the two accuracies as independent samples.
- Testing many models or settings and reporting only the significant one, without a correction such as Bonferroni.
How long your answer should be
3–4 minutes: the table, the one-line statistic, then a sentence interpreting the p-value.
Last checked on 4 December 2026.
Read this
Previous in Probability and statistics: You can draw samples from Uniform, and you have , the inverse CDF of the standard normal . How do you generate samples from a 2D normal distribution , and how do you show that they have the right mean and covariance?
Next in Probability and statistics: Counts are independent Poisson samples. Derive the MLE of . For the counts , what is and the probability that the next count is zero?