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 χ2=(b−c)2/(b+c) (where b and c count the examples on which only one of the two classifiers is right) and the 5% critical value 3.84, 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 χ2=(b−c)2/(b+c) follows approximately a χ12 (chi-square with 1 degree of freedom) distribution.

Steps

  1. Compute the two accuracies: A =(150+25)/200=0.875 and B =(150+10)/200=0.800, a gap of 7.5 percentage points.
  2. Identify the disagreement counts and null hypothesis: let b=25 (A right, B wrong) and c=10 (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 1/2, giving expected counts (b+c)/2=17.5.
  3. Compute McNemar's statistic: without continuity correction, χ2=(25−10)2/35=225/35≈6.43. With the continuity correction, (∣b−c∣−1)2/(b+c)=142/35=5.60.
  4. Compare with the 5% critical value of χ12, which is 3.84: both 6.43 and 5.60 exceed 3.84 (p≈0.011 and 0.018), so we reject the null and conclude A is significantly better than B on this test set (when b+c is below about 25, use an exact binomial test of b out of b+c with p=0.5).
  5. 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

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 ±2 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, MCC=TP⋅TN−FP⋅FN(TP+FP)(TP+FN)(TN+FP)(TN+FN). What do these give for a model that always predicts negative?