Classical machine learning
Model Selection and Error Analysis
Use nested evaluation, error tables, learning curves, uncertainty, and decision memos to select classical models without leaderboard overfitting.
By the end you can
- Design a diagnosis-first sequence of model comparisons
- Explain selection optimism and the role of nested evaluation
- Use error tables, learning curves, slices, and paired uncertainty to compare candidates
- Write a model-selection memo that preserves rationale and limitations
Key idea
Model selection is a sequence of falsifiable comparisons
Trying many algorithms and keeping the highest cross-validation score invites selection noise and post-hoc storytelling. A stronger process begins with a diagnosis and chooses a challenger expected to address it. It then defines the evidence that would justify the added complexity.
The experiment should be able to reject the challenger.
A model family should enter the search because it matches a measured failure, not because it is available in a library.
Visual
A model ladder from problem to deployment
Each rung answers a different uncertainty. Only then is the next justified.
- 1
Problem contract
Confirm unit, cutoff, target, action, and deployment population.
- 2
Baselines
Measure policy, constant, and simple-model performance.
- 3
Failure diagnosis
Identify shape, locality, interaction, probability, or data limitations.
- 4
Targeted challengers
Choose families whose bias addresses the diagnosed failure.
- 5
Nested selection
Tune and compare without reusing final evaluation evidence.
- 6
Decision review
Balance metrics, uncertainty, slices, cost, and operations.
Comparison
Match common failure patterns to candidate families
This is a shortlist, not an automatic estimator map.
Linear residual curvature
Consider transformations, splines, GAMs, trees, or kernels.
- Check support first
- Preserve a linear baseline
- Validate the new shape
- Avoid blind polynomial expansion
Unstable coefficients
Consider ridge, elastic net, grouped features, or more data.
- Inspect correlation
- Separate prediction from explanation
- Measure path stability
- Do not interpret lasso zeros literally
Local subgroups
Consider KNN, trees, forests, or interactions.
- Define meaningful distance
- Check sparse regions
- Avoid identity memorization
- Test subgroup generalization
Poor probability scale
Consider calibration, sampling correction, or probabilistic alternatives.
- Preserve ranking diagnostics
- Use untouched calibration data
- Check prevalence shift
- Separate threshold policy
Tuning and final evaluation need separate evidence
Cross-validation scores guide hyperparameter and family choices. If the same folds are used to report the selected model as though it were fixed in advance, the estimate reflects selection optimism.
Nested cross-validation or a preserved final test separates the inner selection process from outer performance estimation.
The clearest demonstration of what that separation buys came from microarray data. Published analyses were reporting a leave-one-out error of zero once a handful of genes had been picked out. Ambroise and McLachlan showed in 2002 that the zero was an artefact of doing the gene selection outside the cross-validation loop. Their abstract closes on the result: “Using two published data sets, we demonstrate that when correction is made for the selection bias, the cross-validated error is no longer zero for a subset of only a few genes.” Move the selection inside the loop, or use the .632+ bootstrap, and the zero goes away.
Five years later somebody counted how often the field was still making that mistake in print. Dupuy and Simon analysed 42 studies in detail and reported in 2007 that 21 of them — 50% — contained at least one of three basic flaws. One of the three was “in supervised prediction, a biased estimation of the prediction accuracy through an incorrect cross-validation procedure”.
How large is that optimism? It has been measured on data where the right answer is known in advance. Varma and Simon built “null” datasets of 40 samples and 6,000 features, in which the two classes do not differ at all and the true error rate is therefore 50%. They tuned Shrunken Centroids and SVMs on them, then reported the tuned score as if it were an estimate. From their 2006 abstract: “Even though there is no real difference between the two classes for the "null" datasets, the CV error estimate for the Shrunken Centroid with the optimal parameters was less than 30% on 18.5% of simulated training data-sets.” For the SVM the same thing happened on 38% of datasets. A nested procedure, by contrast, “provides an almost unbiased estimate of the true error”. A 50% problem reported as under 30% is selection optimism with a number on it.
How much nesting everyday practice needs is itself contested, and the disagreement is published rather than folkloric. Wainer and Cawley compared nested against flat cross-validation with 12 algorithms on 115 real binary datasets. Their 2021 conclusion: when there are few hyperparameters to tune, flat cross-validation usually selects an algorithm of practically similar quality.
Over-fitting does not stop at the model. It happens in the model-selection criterion too, and Cawley and Talbot measured how large it gets. In such a criterion, they argued in 2010, “a low variance is at least as important” as unbiasedness, because “a non-negligible variance introduces the potential for over-fitting in model selection as well as in training the model”. And “the degradation in performance due to over-fitting the model selection criterion can be surprisingly large”.
Then they put numbers on it. Thirteen benchmark data sets, each repeated across 100 realisations — 20 for the image and splice sets. “The p-value is below 0.05 for five of the thirteen benchmarks, indicating that in each case the median protocol is significantly biased in favour of the RBF KRR classifier”. A protocol that tilts that way, they conclude, “does not provide a reliable protocol for comparing the performance of machine learning algorithms”.
Their general warning is the one that matters here. These effects “are often of comparable magnitude to differences in performance between learning algorithms, and thus cannot be ignored in empirical evaluation”. The gap between two models can be smaller than the wobble in how you picked them.
Example
An error table can be more useful than another leaderboard
For every candidate, record where it improves and where it creates new failure. Two published error tables show how much a single aggregate number can hide.
A widely implemented proprietary sepsis alert was measured against one health system's own records. Across 38,455 hospitalizations of 27,697 patients at Michigan Medicine, the Epic Sepsis Model reached a hospitalization-level AUC of 0.63 (95% CI 0.62–0.64). It fired on 6,971 of those hospitalizations, 18%. It did not identify 1,709 of the 2,552 patients who developed sepsis, 67%. Wong and colleagues put the conclusion in one sentence in JAMA Internal Medicine in 2021: “This external validation cohort study suggests that the ESM has poor discrimination and calibration in predicting the onset of sepsis.” In 2024 a second team repeated the exercise on the same vendor model across two county emergency departments, over 145,885 encounters, and reported a sensitivity of 14.7%, a specificity of 95.3% and a positive predictive value of 7.6%.
The second table is about slices. Three commercial gender classifiers were audited against a new 1,270-person benchmark in 2018, and the errors were not spread evenly. Buolamwini and Gebru: “We evaluate 3 commercial gender classification systems using our dataset and show that darker-skinned females are the most misclassified group (with error rates of up to 34.7%). The maximum error rate for lighter-skinned males is 0.8%.” One aggregate accuracy figure covers both of those numbers.
The federal evaluation found the same shape of result at a different scale. NIST put 18.27 million images of 8.49 million people through 189 algorithms from 99 developers and published the result in December 2019. False positive rates across demographic groups, it reported, “often vary by factors of 10 to beyond 100 times”. The same report instructs that both false negative and false positive rates be reported for each demographic group at the operating threshold. Which is to say: the error table is the deliverable.
- High-income tail: linear model extrapolates smoothly, while forest underpredicts because leaves cannot extend the trend.
- Rare category: one-hot logistic model is stable, while target encoding overfits categories with few examples.
- Boundary cases: SVM improves ranking but its uncalibrated margins produce poor risk estimates.
- Missing sensor: tree handles historical absence well, but performance collapses when the missingness mechanism changes.
- Latency slice: KNN performs strongly offline but violates online p99 requirements at peak load.
- Boundary cases: SVM improves ranking but its uncalibrated margins produce poor risk estimates.
Steps
Run a diagnosis-first selection cycle
Keep the candidate set small enough to understand.
1. Freeze evaluation rules
Specify split, metric, slices, thresholds, and comparison tolerance.
2. Characterize the baseline
Inspect residuals, calibration, support, and operational cost.
3. Write challenger hypotheses
State which failure each family should improve.
4. Tune inside the inner loop
Fit every learned transformation and setting without outer-fold leakage.
5. Compare uncertainty and slices
Use paired fold results, learning curves, and case review.
6. Select and document
Choose the total-value winner and preserve rejected alternatives.
Analogy
A clinical differential diagnosis for model failure
A clinician observes symptoms, lists a few plausible causes, and orders the tests that distinguish them; ordering every possible test would create noise, cost, and incidental findings without clearer reasoning.
Model experiments are not medical trials, and their outcomes depend on resampling and tuning. The shared lesson is to let a diagnosis drive the next test.
Model search becomes credible when each challenger is linked to a specific observed limitation.
Key idea
Repeated leaderboard inspection consumes the test set
Every choice influenced by test performance adapts the project to that supposedly unseen sample, and the file remains unchanged while its informational role is exhausted.
Restrict access, record decisions, and acquire fresh evidence when the test has guided development.
A leaderboard is not a fixed evaluation, and in 2015 the problem was written down as an algorithmic one. Blum and Hardt start from what repeated submission does. “What makes this estimation problem particularly challenging is its sequential and adaptive nature. As participants are allowed to repeatedly evaluate their submissions on the leaderboard, they may begin to overfit to the holdout data that supports the leaderboard.” On the state of the defences they are blunt. “Few theoretical results give actionable advice on how to design a reliable leaderboard. Existing approaches therefore often resort to poorly understood heuristics such as limiting the bit precision of answers and the rate of re-submission.” Their own algorithm withstands “practical adversarial attacks”, checked against “real submission files from a Kaggle competition”. A team that keeps looking at its own test set is running the same adaptive process. It is running it with none of those defences in place.
Finding out what a much-used test set still measures costs a second test set. The CIFAR-10 and ImageNet test sets were rebuilt from scratch, following the original collection processes, and the models were run again. The 2019 result: “We evaluate a broad range of models and find accuracy drops of 3% - 15% on CIFAR-10 and 11% - 14% on ImageNet.” Recht and colleagues read the drops as not caused by adaptivity — which is the honest complication in this section, not a footnote to it.
The argument then continued. A second team re-analysed the same replication in 2020 and found that once statistical bias in the replication procedure is corrected, only an estimated 3.6% ± 1.5% of the original 11.7% ± 1.0% drop remains unaccounted for. Rebuilding the benchmark, and then two teams disagreeing about the residual, is what it takes to establish how much information a heavily re-used holdout has left.
A test set is a finite information resource, not a permanent scoreboard.
Tiny score differences rarely justify strong conclusions
Fold results are correlated, datasets are finite, and metric estimates vary across sampling, labels, and thresholds. Report distributions, paired differences, and practical tolerances rather than ranking models to three decimals.
A simpler candidate within uncertainty can be preferable under cost, stability, or governance constraints.
How much distance between two classifiers is real? One comparison ran at a scale that settles the question: 179 classifiers from 17 families, on 121 data sets, published in 2014. The best random forest reached 94.1% of the maximum accuracy. The runner-up was close enough that the ranking does not survive a test. “However, the difference is not statistically significant with the second best, the SVM with Gaussian kernel implemented in C using LibSVM, which achieves 92.3% of the maximum accuracy.” An independent repeat in 2016 used 14 families on 115 real binary datasets and found random forest, GBM and RBF SVM not significantly different from one another. Its author, Wainer, proposed that a change of less than 0.0112 in error rate be treated as irrelevant. That is a published figure for how small a difference is too small to act on.
Which test should compare classifiers across many data sets? In 2006 the question had barely been asked. Demšar noted that comparing two algorithms on a single data set “has been scrutinized for quite some time already”, but that “the issue of statistical tests for comparisons of more algorithms on multiple data sets, which is even more essential to typical machine learning studies, has been all but ignored”. He reviewed practice, examined the candidate tests “theoretically and empirically”, and recommended “a set of simple, yet safe and robust non-parametric tests”. Those are “the Wilcoxon signed ranks test for comparison of two classifiers and the Friedman test with the corresponding post-hoc tests for comparison of more classifiers over multiple data sets”. Such a comparison is usually reported with a critical-difference diagram: a rank axis with bars joining the candidates that cannot be told apart. The same paper introduced it.
Position
Most model comparisons are comparisons of protocols
A table of scores is read as a comparison of algorithms. Usually it is not one. The finding in this lesson is that over-fitting introduced by the model-selection step is “often of comparable magnitude to differences in performance between learning algorithms”. So when two candidates finish close together, what has been measured is how each of them was tuned: with what budget, by whom, and how many times. The scale of the effect is not hypothetical. Tuning on data with no signal at all produced reported error under 30% where the truth was 50% — on 18.5% of datasets for one method, and 38% for the other.
That is not a counsel of despair, because a procedural failure has procedural fixes. Selection and estimation need separate evidence, which is what a nested design buys. It is what the corrected loop bought Ambroise and McLachlan, turning a leave-one-out error of zero back into a real number. A test set is consumed by being consulted. Blum and Hardt were designing for a public competition, but the mechanism they describe needs no competition to occur: one holdout, evaluated repeatedly, each attempt shaped by the last. Only a team and a file. And a ranking of means across data sets is not a comparison at all. Demšar's paper exists because that question had “been all but ignored”, and it supplies both the tests and the diagram in which candidates that cannot be told apart are drawn joined together. When 179 classifiers are run on 121 data sets, the winner's 94.1% and the runner-up's 92.3% are drawn joined together too.
The practical form of this position is a habit rather than a technique. Before reporting that A beat B, write down what the two runs did not have in common: search budget, preprocessing, how often each was looked at, and who wanted which one to win. When that list is long, the difference in the final column is not a fact about A and B. And decide in advance how small a gap you will refuse to act on. Wainer's answer for classification error was 0.0112.
When the protocol moves the number as much as the model does, the ranking is a fact about the protocol.
Learning curves separate data limits from family limits
Plot training and validation behavior as the training set grows. A persistent high-bias plateau suggests representation or model limitations. A narrowing gap can indicate value from more independent data.
Curves should preserve time, group, and pipeline boundaries. Otherwise they can repeat the same leakage at several sample sizes.
More data is an intervention whose expected benefit should be diagnosed, not assumed.
The final decision should be readable without the notebook
A model-selection memo should state the problem contract, candidate rationale, data versions, split, metrics, uncertainty, slice results, calibration, cost, known failures, and rollback conditions.
This makes the choice auditable when people, data, and software change.
That list is not an invention of this lesson. TRIPOD+AI is a 27-item reporting checklist for prediction model studies, with a further 13-item checklist for abstracts, published in the BMJ in April 2024. It came out of two Delphi rounds — 170 respondents from 22 countries, then 200 from 27 countries — and a consensus meeting attended by 28 participants, and it explicitly supersedes the TRIPOD checklist of 2015. Its scope is deliberately indifferent to which family you selected: “TRIPOD+AI provides harmonised guidance for reporting prediction model studies, irrespective of whether regression modelling or machine learning methods have been used”.
What happens when the memo is not written has also been measured. A 2025 review examined 140 articles reporting multivariable prognostic models in the three top-indexed general radiology journals. “Only 4% (n = 6) cited TRIPOD, with just 1 including the checklist. TRIPOD adherence was poor overall, with a median score of 57% (interquartile range, IQR 48% to 64%, range 30% to 87%).” In the statistical analysis domain — splits, metrics, uncertainty, the part this lesson is about — adherence was 5%.
A reproducible decision record is part of the model artifact.
Key takeaways
- Model families should be proposed as hypotheses about measured baseline failures, not added to an indiscriminate search; across 179 classifiers from 17 families on 121 data sets, the best random forest's 94.1% and the runner-up SVM's 92.3% were not significantly different.
- Tuning and final evaluation require separate evidence: on "null" datasets of 40 samples and 6,000 features where the true error is 50%, the tuned-and-reported cross-validation error fell below 30% on 18.5% of datasets for Shrunken Centroids and on 38% for the SVM, while nested cross-validation recovered a near-unbiased estimate.
- Error tables reveal where a candidate improves, fails, shifts burden, or violates operations beyond one aggregate score — an AUC of 0.63, alerts on 18% of hospitalizations and 67% of sepsis patients unidentified is the table that a headline accuracy figure would have hidden.
- Learning curves can distinguish likely data limitations from representation or family limitations when splits remain valid.
- Small metric differences should be interpreted with resampling uncertainty, practical tolerances, and system costs; one published threshold puts practical irrelevance at a change of less than 0.0112 in error rate.
- A model-selection memo preserves the evidence, rationale, rejected alternatives, known failures, and rollback conditions; TRIPOD+AI specifies 27 items for exactly this, and a review of 140 published prognostic models found 4% citing it and 57% median adherence.