CV Courseversity

Model Evaluation and Experimental Design

Covers evaluation metrics, cross-validation and baselines, probability calibration, statistical significance testing for comparing learning algorithms, and systematic error analysis.

“A hospital is deciding whether to replace its current sepsis-risk model with a new one that scored two percentage points higher on a single held-out test set. Two points sounds real, but the test set had only four hundred positive cases, the "improvement" could plausibly be noise from which patients happened to land in that split, and nobody has checked whether the new model's predicted risk of 70 percent actually corresponds to a 70 percent chance of sepsis. What has to be true before that two-point difference is evidence of anything at all?”

Validation, Baselines, and the Two Cultures of Modeling · 15 min

The most basic failure in model evaluation is measuring performance on the same data used to fit the model, which produces an optimistic estimate that says more about the model's capacity to memorize than its ability to generalize — a problem sometimes called the shrinkage phenomenon, because performance reliably shrinks when measured on genuinely new data. Mervyn Stone's 1974 paper formalized cross-validation as a systematic remedy: repeatedly set aside part of the data, fit the model on what remains, evaluate on the held-out part, and average the results across every way of doing this split. Stone's key conceptual move was to treat cross-validation not merely as a way to assess a fixed model's accuracy after the fact, but as a way to choose among competing models or hyperparameters in the first place, using only held-out performance as the criterion, which avoids the circularity of using training fit to both select and evaluate a model.

Any measured accuracy number is meaningless without a baseline to compare it against, and the choice of baseline shapes what a result can honestly claim. A majority-class baseline that always predicts the most common label reveals whether a model is doing better than chance in a way that accounts for class imbalance, while a simple linear or rule-based baseline reveals whether the complexity of a more sophisticated model is actually earning its keep. Leo Breiman's essay "Statistical Modeling: The Two Cultures" argued that a large share of statistical practice implicitly evaluates models by goodness-of-fit on the data used to build them and by whether a specified stochastic mechanism seems plausible, whereas a smaller, largely separate tradition — more common in machine learning than in classical statistics — evaluates models purely by predictive accuracy on data the model never saw during fitting, treating the true data-generating mechanism as unknown and possibly irreducibly complex.

Breiman's critique was not that goodness-of-fit statistics are worthless, but that they lose diagnostic power in high dimensions, that multiple substantially different models can fit historical data about equally well while implying contradictory conclusions about which variables matter, and that a model can look excellent by every in-sample measure while making poor predictions on new data — precisely because in-sample fit and out-of-sample generalization are different quantities that happen to coincide only when a model's assumptions are approximately correct and it has not been allowed to overfit. His prescription, held-out predictive accuracy as the primary criterion for judging a model, is now standard practice across the field, but the underlying reason it works traces directly back to the same generalization-versus-memorization distinction that cross-validation exists to police. A model that fits historical data impressively but has never been checked against genuinely unseen cases has, by Breiman's account, not yet demonstrated anything about its usefulness for prediction, however elegant its underlying statistical story may be.

Probability Calibration · 14 min

A classifier can rank examples correctly by relative risk while still producing predicted probabilities that are systematically wrong in absolute terms, and calibration is the property that closes this gap: a model is well calibrated if, among all the examples it assigns a predicted probability of, say, 0.7, roughly seventy percent actually belong to the positive class. Alexandru Niculescu-Mizil and Rich Caruana's empirical study of calibration across many supervised learning methods found that different algorithm families are miscalibrated in characteristically different ways. Maximum-margin methods such as boosted trees, support vector machines, and boosted stumps tend to push predicted probabilities away from zero and one, producing a sigmoid-shaped distortion because their training objectives care about the margin between classes rather than about the calibrated probability of class membership, while naive Bayes tends to push probabilities toward the extremes because its conditional-independence assumption is typically violated in real data, compounding overconfident evidence. Neural networks and bagged decision trees, by contrast, were found to produce comparatively well-calibrated probabilities without any additional adjustment.

Two standard post-hoc corrections address these distortions once a model's raw outputs are known to be systematically biased in shape. Platt scaling, developed by John Platt and analyzed further by Hsuan-Tien Lin, Chih-Jen Lin, and Ruby Weng, fits a sigmoid function to a held-out calibration set, mapping the model's raw scores through the function Pr(y=1|x) ≈ 1 / (1 + exp(Af + B)) with parameters A and B chosen to minimize a likelihood-based loss on that calibration data; it works well when the distortion is itself sigmoid-shaped and when only a small calibration set is available. Isotonic regression instead fits an arbitrary non-decreasing function to the calibration data, which can correct any monotonic distortion rather than only a sigmoid one, but because it has more free parameters it typically needs a larger calibration set to avoid overfitting the correction itself. Both corrections are fit on data held out from the original training set, since reusing training data for calibration would risk fitting the correction to the same overconfident pattern it is meant to remove.

Niculescu-Mizil and Caruana's key practical finding was that the best choice of correction depends on which distortion a given algorithm exhibits and how much calibration data is available, and that after an appropriate correction, methods including boosted trees, random forests, and support vector machines — none of which produce well-calibrated probabilities on their own — can match or exceed the calibrated performance of methods that were well behaved from the start. Calibration matters most whenever a predicted probability will be used directly, for instance to set a decision threshold, to compare risk across patients, or to weight a downstream cost calculation, since a model that ranks correctly but reports the wrong absolute probability can silently mislead any of these uses even while its ranking-based accuracy metric looks fine. A weather model that ranks tomorrows correctly by relative rain risk but reports 90 percent when the true chance is 60 percent, for instance, will lead anyone who takes the number at face value to systematically over-prepare for rain, even though the model's discrimination between rainy and dry days is genuinely good.

Statistical Testing and Error Analysis · 15 min

A single accuracy difference between two models measured on one test set is a noisy estimate, not a fact, because the specific examples in that test set, and the specific random draws underlying training, both introduce variability that a point estimate alone cannot reveal. Thomas Dietterich's 1998 analysis showed that the intuitive fix — running k-fold cross-validation and applying a standard paired t-test to the resulting fold-by-fold accuracy differences — is statistically unsound, because the folds share overlapping training data and are evaluated on overlapping or dependent portions of the same dataset, violating the independence assumption the t-test requires and inflating the apparent significance of differences that may not be real. Dietterich evaluated several proposed alternatives against this problem and found that none was uniformly best, but that a test he called 5x2cv — repeating twofold cross-validation five times, computing a variance estimate from the resulting differences, and applying a modified statistic with the appropriate degrees of freedom — had the lowest rate of falsely declaring a difference significant among the methods he tested.

Statistical significance testing answers a narrower question than practitioners often assume: it addresses whether an observed difference is unlikely to have arisen from sampling variability alone, not whether the difference is large enough to matter in practice, and not whether the comparison generalizes beyond the specific dataset and evaluation protocol used. A model can be statistically significantly better while the improvement is operationally negligible, and conversely a genuinely important improvement can fail to reach significance on a small test set simply because the test lacked statistical power. Reporting both a significance test and a practical effect size, together with the sample size the conclusion rests on, is necessary for a comparison to be interpretable rather than merely impressive-looking. Two models separated by a statistically significant but operationally trivial margin, and evaluated only on a benchmark that does not resemble deployment conditions, provide little basis for a real deployment decision even though the comparison technically passed a significance test.

Beyond a single aggregate metric, rigorous evaluation requires error analysis: examining which specific examples a model gets wrong, whether errors cluster in particular subpopulations, input types, or label categories, and whether a model's mistakes are concentrated in cases that matter more for the deployment context than an average metric would suggest. A model with strong overall accuracy can still systematically fail on a minority subgroup, a rare but consequential class, or an input distribution shift that has not yet shown up in aggregate statistics, and none of these patterns is visible from an accuracy number alone — they require deliberately slicing the evaluation data and inspecting misclassified examples directly, which turns evaluation from a single verdict into a diagnostic process. This kind of slicing is what separates a scorecard from an investigation, and it is often the step that reveals whether an aggregate metric improvement actually represents broad-based progress or merely a shift in where the errors are concentrated.

Practice

Reading a Calibration Reliability Diagram

1.0 0.0 predicted probability observed frequency perfect calibration bin 1: pred 0.2, obs 0.16 (n=50) bin 2: pred 0.5, obs 0.60 (n=30) bin 3: pred 0.8, obs 0.95 (n=20) ECE = 0.5(0.04) + 0.3(0.10) + 0.2(0.15) = 0.08

Three probability bins from a 100-example calibration set: bin 1 (n=50) predicts 0.20 on average but only 16% are positive; bin 2 (n=30) predicts 0.50 but 60% are positive; bin 3 (n=20) predicts 0.80 but 95% are positive. Weighting each bin's absolute gap by its share of the data gives an Expected Calibration Error of 0.5×0.04 + 0.3×0.10 + 0.2×0.15 = 0.08.

  • Held-out evaluation exists to distinguish a model that has learned generalizable structure from one that has merely memorized its training data, and Stone's cross-validation formalizes this as a model-selection criterion, not just a post-hoc score.
  • A model can rank examples correctly while its predicted probabilities are systematically wrong in a characteristic, algorithm-family-specific way, which is why calibration methods like Platt scaling and isotonic regression are chosen based on the shape of the distortion and the amount of calibration data available.
  • A statistically significant difference between two models answers only whether the difference is unlikely to be sampling noise — it says nothing about whether the difference is practically meaningful or whether the comparison will hold up on new data, and naive t-tests on cross-validation folds specifically overstate significance because the folds are not independent.

Recall Practice

Two culturesClick to reveal
What is Breiman's core critique of evaluating a model primarily by goodness-of-fit on the data used to build it?
Goodness-of-fit loses diagnostic power in high dimensions, multiple very different models can fit the same historical data about equally well while implying contradictory conclusions, and strong in-sample fit does not guarantee strong out-of-sample predictive accuracy, which is the quantity that actually matters for deployment.
Calibration gapClick to reveal
What does it mean for a classifier to be well calibrated, distinct from being accurate?
Calibration means that among examples assigned a given predicted probability, the actual fraction that are positive matches that probability — for example, roughly 70% of examples predicted at 0.7 are truly positive — which is a separate property from whether the model correctly ranks examples by relative risk.
5x2cvClick to reveal
Why did Dietterich propose the 5x2cv test instead of a standard paired t-test on cross-validation folds?
Standard k-fold cross-validation folds share overlapping training data and dependent evaluation sets, violating the independence assumption the t-test requires; 5x2cv repeats twofold cross-validation five times and uses a modified statistic that better accounts for this dependence, giving the lowest false-positive rate among the methods Dietterich tested.
Error analysisClick to reveal
Why can a model with strong overall accuracy still be unsafe to deploy?
Aggregate accuracy can hide systematic failures concentrated in a minority subgroup, a rare but consequential class, or a distribution shift not yet reflected in the evaluation data; only slicing the evaluation by subpopulation and inspecting misclassified examples directly can reveal these concentrated failure patterns.

Glossary

Cross-validation
A resampling procedure that repeatedly holds out part of the data for evaluation while fitting on the rest, used both to estimate generalization performance and to select among models or hyperparameters.
Baseline
A simple reference model — such as a majority-class predictor or a basic linear model — against which a more sophisticated model's performance is compared to determine whether its added complexity is actually earning better results.
Calibration
The property that a model's predicted probabilities match observed frequencies, so that among examples predicted at probability p, roughly a fraction p are actually positive.
Platt scaling
A calibration method that fits a sigmoid function to a model's raw scores using a held-out calibration set, correcting sigmoid-shaped miscalibration with relatively little calibration data.
Isotonic regression (for calibration)
A calibration method that fits an arbitrary non-decreasing function to correct any monotonic miscalibration, more flexible than Platt scaling but requiring more calibration data to avoid overfitting.
Statistical significance (in model comparison)
A measure of whether an observed performance difference between models is unlikely to have arisen from sampling variability alone, distinct from whether the difference is practically large or will generalize to new data.
Practical Activity

Hand-Compute McNemar's Test for Comparing Two Classifiers

A fully worked, paper-and-pencil exercise: given a 2x2 disagreement table for two classifiers evaluated on the same test set — 18 cases where classifier A is correct and B is wrong, and 6 cases where B is correct and A is wrong — compute McNemar's test statistic with continuity correction by hand, (|18-6|-1)^2/(18+6), and compare the result to the chi-square critical value for one degree of freedom at the 0.05 significance level to decide whether the difference between the classifiers is statistically significant. No software or real dataset is used; the contingency-table counts are given directly and every arithmetic step is shown and checked.

Ready to test yourself?

5 questions on this module.

Start Quiz