Two classifiers A and B are evaluated on the same 200 test examples. Both are right on 150, both are wrong on 15, only A is right on 25 and only B is right on 10. Test at the 5% level, using McNemar's statistic (where and count the examples on which only one of the two classifiers is right) and the 5% critical value , whether the difference in accuracy is real. Why not simply compare the two accuracies?
ML systems and evaluation, Evaluation statistics
Level L2 Elementary. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you know the paired test for comparing two classifiers on one test set and can compute it from the disagreement counts.
Key idea
Only the examples where the classifiers disagree carry information. Under the null hypothesis each disagreement is equally likely to favour either classifier, so the statistic follows approximately a (chi-square with 1 degree of freedom) distribution.
Steps
- Compute the two accuracies: A and B , a gap of percentage points.
- Identify the disagreement counts and null hypothesis: let (A right, B wrong) and (A wrong, B right); the 150 and 15 agreements cancel out. Under the null hypothesis of equal error rates, each disagreement favours A with probability , giving expected counts .
- Compute McNemar's statistic: without continuity correction, . With the continuity correction, .
- Compare with the 5% critical value of , which is : both and exceed ( and ), so we reject the null and conclude A is significantly better than B on this test set (when is below about 25, use an exact binomial test of out of with ).
- Explain why comparing the two accuracies alone is inferior: comparing raw accuracies ignores that both models were evaluated on the exact same 200 examples; McNemar's paired test removes example-to-example variation and has greater statistical power.
Common mistakes
- Including the 150 and 15 agreement counts in the statistic. They cancel out of the test.
- Using the unpaired two-proportion -test, which ignores the pairing and so has less power.
- Concluding that A is better in general. The test only says so for this test distribution, and it does not account for variation from retraining.
How long your answer should be
Half a page; 5 minutes.
Read this
Previous in ML systems and evaluation: A classifier gets 340 of 400 test examples right. Give an approximate 95% confidence interval for its true accuracy. How large must the test set be to estimate accuracy to within percentage points at 95% confidence, if you have no prior idea of the accuracy?
Next in ML systems and evaluation: A classifier on 1,000 test examples has TP = 10, FN = 10, FP = 5 and TN = 975. Compute the accuracy, the F1 score and the Matthews correlation coefficient, . What do these give for a model that always predicts negative?