Lab 03 — Regression Detection with McNemar's Test

Phase: 09 — Model Accuracy Evaluation | Difficulty: ⭐⭐⭐⭐⭐ | Time: 3–4 hours

McNemar's test is the correct statistical test for detecting accuracy regressions between two models on the same dataset.

What you build

  • mcnemar_test — χ² statistic and p-value for paired categorical comparisons
  • RegressionDetector — stores baseline, compares new model per-task
  • RegressionPolicy — per-task delta gate + average delta gate for CI pass/fail
  • analyze_slices — break down accuracy by data slice (domain, length, etc.)
  • RegressionResult — full report with pass/fail status

Key concepts

ConceptWhat to understand
McNemar's testFor paired binary outcomes: χ²=(
b, c cellsb = old correct, new wrong; c = old wrong, new correct
Why not t-test?McNemar handles correlated binary pairs — t-test assumes independence
CI regression gatep < 0.05 AND delta > threshold → block deployment

Files

FilePurpose
lab.pyStubs with TODO markers
solution.pyComplete working implementation
test_lab.pypytest suite
requirements.txtDependencies

Run

pip install -r requirements.txt
python lab.py
pytest test_lab.py -v