Two classifiers evaluated on the same test set will each get some samples right and wrong. Samples both get right, or both get wrong, say nothing about which is better; only the samples where they disagree matter. McNemar's test asks whether the disagreements lean one way more than chance would explain.
Implement mcnemar_statistic(y_true, pred_a, pred_b) and return the continuity-corrected chi-square statistic computed from the two disagreement counts.
b be the number of samples only A got right and c the number only B got right.max(|b - c| - 1, 0)**2 / (b + c) as a Python float, or 0.0 when b + c == 0.Open one at a time. Each gives away a little more than the last.
Build two boolean arrays, a_correct and b_correct, by comparing each prediction to y_true.
b counts a_correct & ~b_correct; c counts ~a_correct & b_correct.
No results yet
Run your code to check it against the examples, or submit to run every test.