AI & Machine Learning Master Course — 030. Statistics lab: audit a claimed improvement
Smartyfy AI & Machine Learning Master Course
Course ID: smartyfy-ai-ml-master-200
Lesson 030: Statistics lab: audit a claimed improvement
Prerequisites: Lesson 029. Learning outcome: Evaluate whether an observed gain is meaningful, uncertain, or selection-driven.
1. Translate a headline into a checkable claim
A fictional model report says, “Our classifier reduces errors by twenty percent.” The baseline correctly classifies 160 of 200 examples, while the candidate correctly classifies 168. Baseline accuracy is 80 percent and candidate accuracy is 84 percent. The absolute accuracy gain is four percentage points. Errors fall from 40 to 32, which is an eight-error reduction divided by 40, or twenty percent relative error reduction.
Both statements can be arithmetically correct while creating different impressions. An audit records the numerator, denominator, metric definition, evaluation population, and comparison baseline. Ask whether the baseline received comparable tuning effort and whether the new model adds latency, maintenance, or failure risks. A relative gain alone cannot establish operational value.
For this lab, the intended decision is whether to replace a fixed classifier for future independent service requests. The team previously declared that an absolute gain of at least three percentage points would justify the extra cost, provided important subgroups do not deteriorate materially. That threshold belongs in the audit before anyone interprets statistical significance.
2. Recover the paired evidence
The models predict the same examples, so record their joint outcomes. Both are correct on 148 examples. The baseline alone is correct on 12, the candidate alone on 20, and both are wrong on 20. These four counts sum to 200 and reproduce both marginal accuracies. Marginal scores without this pairing hide which cases actually changed.
Define a per-example difference as candidate correctness minus baseline correctness. It is one on 20 improvements, minus one on 12 regressions, and zero on 168 ties. Its average is (20 − 12)/200 = 0.04. This paired difference is the natural unit for a sample-level uncertainty calculation when examples are genuinely independent.
Among the 32 disagreements, the candidate wins 20. Under a null of equal marginal correctness probabilities, conditioning on the total disagreements yields a binomial comparison with success probability one half. The exact two-sided binomial test gives a p-value near 0.215. This exact paired test is often presented as an exact version of McNemar’s test.
Our result is compatible with a range of underlying gains. A paired percentile bootstrap gives an approximate 95 percent interval around −1.5 to 9.5 percentage points. The interval includes no gain, possible harm, and gains above the practical threshold. It does not establish equivalence, failure, or a reliable improvement above three points.

3. Audit the experiment that produced the report
Now the experiment log reveals forty candidate variants were evaluated on these same 200 examples, and the best was selected. Several thresholds and two alternative metrics were also inspected. The displayed p-value and interval describe the winner as if it had been fixed before evaluation. They do not account for that selection and therefore cannot serve as an untouched confirmatory evaluation.
Do not repair this history by renaming the reused set “test” or by computing more bootstrap repetitions. The selected model was influenced by its outcomes. Treat the 200 examples as development data, document the search, freeze the candidate and baseline, and evaluate a new representative sample under a declared plan. If data are limited, nested cross-validation can estimate the performance of a selection procedure when its split design fits the task.
Check for more direct leakage as well. Were imputation, scaling, feature selection, and thresholds fitted using evaluation data? Did duplicate requests or the same customers cross partitions? Did a feature become available only after the prediction decision? Any of these can manufacture apparent gains even before statistical selection is considered.
4. Separate the sources of uncertainty
Our bootstrap resamples fixed predictions and therefore addresses evaluation-example variation conditional on the trained models. It does not include variation from retraining, choosing different random seeds, or repeating the entire forty-model search. It also assumes independent examples from the relevant population. Repeated requests from customers need a customer-aware design; forecasting needs chronology and a realistic future horizon.
Review subgroup counts and errors, but resist presenting dozens of tiny slices as definitive discoveries. Sparse groups can have very wide uncertainty, and searching many groups creates multiplicity. Predeclare critical slices when possible and use exploratory findings to motivate further data collection. A global mean gain does not imply every group benefits.
The decision record should distinguish evidence from action. A defensible conclusion here is: the observed development gain is four points, but sampling uncertainty and winner selection prevent a confirmed deployment claim. Request a frozen evaluation with the practical threshold, primary metric, comparison direction, exclusion rules, and stopping plan written down. Avoid inventing a required sample size without assumptions about plausible effect and variability.
5. Reproduce the audit’s numerical core
Run this original synthetic example with Python 3.10 or later, NumPy 1.24 or later, and SciPy 1.10 or later. It runs on a CPU without an account, API key, or paid service. The seed makes the illustrative bootstrap reproducible in the stated environment. The assertions check the confusion of units most likely to distort a headline: proportions, percentage points, and relative error reduction.
The output is a four-percentage-point gain, twenty-percent relative error reduction, and exact paired p-value approximately 0.215327. The resampled interval is descriptive for these fixed predictions. The discovery of model selection changes how we may use it, not the arithmetic printed by the program.
import numpy as np
from scipy.stats import binomtest
old = np.array([1]*148 + [1]*12 + [0]*20 + [0]*20)
new = np.array([1]*148 + [0]*12 + [1]*20 + [0]*20)
d = new - old
wins, losses = np.sum(d == 1), np.sum(d == -1)
result = binomtest(int(wins), int(wins + losses), p=0.5)
rng = np.random.default_rng(30)
boot = rng.choice(d, size=(20000, len(d)), replace=True).mean(axis=1)
interval = np.quantile(boot, [0.025, 0.975])
relative_error_reduction = (old.mean() - new.mean()) / (old.mean() - 1)
assert (wins, losses) == (20, 12)
assert np.isclose(d.mean(), 0.04)
assert np.isclose(relative_error_reduction, 0.20)
print("gain in percentage points:", round(100*d.mean(), 3))
print("relative error reduction percent:", round(100*relative_error_reduction, 3))
print("paired exact p:", round(result.pvalue, 6))
print("bootstrap interval, percentage points:", np.round(100*interval, 3))
Practice: four questions with worked answers
1. A baseline has 100 errors and a candidate has 90 among one thousand cases. Report both improvements.
Answer: Errors fall by 10/100 = 10 percent relatively. Accuracy rises from 90 to 91 percent, an absolute gain of one percentage point. Preserve both denominators.
2. Why do 20 wins and 12 losses matter more for the paired test than 168 ties?
Answer: Only disagreements distinguish model correctness. Conditioning on 32 disagreements gives a binomial null with probability one half for a candidate win; ties still matter for the overall gain denominator.
3. What changes after learning that forty models used the same evaluation set?
Answer: The winning score reflects selection. Treat that set as development evidence and freeze a candidate before fresh evaluation, or evaluate a properly nested selection procedure. Extra bootstrap draws cannot erase selection.
4. The interval includes zero and the required three-point gain. What conclusion follows?
Answer: The evidence is insufficient to establish either a useful gain or no useful gain. Report the range, uncertainty, and selection limitations; collect an appropriately designed confirmation sample before claiming success.
Knowledge check: five explained MCQs
1. An 80-to-84 percent accuracy change is: A. Four percentage points. B. Four percent relative error reduction. C. Twenty percentage points.
Correct: A. The absolute difference is 84 minus 80; relative error reduction uses a different denominator.
2. Which is the relevant resampling object here? A. Unmatched model averages. B. Paired per-example outcomes. C. Only correct candidate cases.
Correct: B. Pairing retains the dependence from shared examples.
3. Selecting the best of forty test scores: A. Leaves the test untouched. B. Guarantees generalization. C. Makes that set part of development.
Correct: C. Selection used its outcomes to influence the final choice.
4. The bootstrap shown captures: A. Evaluation-sample variation for fixed predictions. B. Every retraining effect. C. All future shifts.
Correct: A. Training, search, and distribution-change uncertainty are not repeated in this computation.
5. A useful audit conclusion should include: A. Only the winning p-value. B. Effect, uncertainty, selection history, and decision threshold. C. Only the model name.
Correct: B. These explain both what was observed and what action the evidence supports.
Common pitfalls
Do not mix relative percentages with percentage points, ignore pairing, or report a winner’s ordinary interval as selection-adjusted evidence. A reused test set, leaked preprocessing, and shifted deployment population are distinct issues that a sophisticated statistical test cannot automatically solve.
Summary
Auditing a claimed gain requires reconstructing both arithmetic and experiment history. Match the uncertainty calculation to the sampling unit, account for the search, and compare plausible effects with a practical threshold. When evidence remains inconclusive, preserve that conclusion and design the next evaluation honestly.