CS 460G Midterm Hub / Lectures / Week 5 Lecture 3
Week 5 · Lecture 3

Validation & Evaluation

Holdout, stratified splits, repeated holdout, bootstrap, 3-way holdout, k-fold, LOO.

short answercoding Q

Every validation scheme in the course, on one deck. This is where the "why a validation set" and "k-fold vs LOO" answers come from.

Why evaluate at all

Three reasons, in the deck's numbering:

  1. To estimate generalisation performance — performance on future, unseen data; the training objective is only a proxy.
  2. To increase predictive performance — tweak the learning algorithm within a hypothesis space, and select the best-performing model.
  3. To identify the best algorithm for the problem — compare different algorithms on the same footing.
Three reasons to care about evaluation
Three reasons to care about evaluation · slide 17

Parameters versus hyperparameters

Model parametersHyperparameters
Definitionparameters of the model itselftuning parameters of the algorithm
Learned?yes — fitted to training datano — set beforehand
Examplesweights $w$ in linear regression$k$ in k-NN, $C$ and $\gamma$ in SVM, tree depth
Parameters vs hyperparameters
Parameters vs hyperparameters · slide 22

That table answers the practice question about the role of $C$: $C$ is a hyperparameter, selected by validation, never fitted by the optimiser.

The splits, from weakest to strongest

Random subsampling / holdout

Assumption: the dataset is representative of the true population. Split randomly into train and test.

Never judge your model's performance on the training data. It is on the slide in red, and it is the reason every notebook prints test accuracy and not train accuracy.

Holdout's documented problems:

  • violation of independence
  • changing class proportions
  • not suited to limited data
  • performance varies a lot with which points happened to be held out
  • bias in model evaluation
  • lack of variability in the data
Holdout validation and its six problems
Holdout validation and its six problems · slide 36

Stratified split

The failure mode — a test set with no versicolor at all
The failure mode — a test set with no versicolor at all · slide 32
Stratification restores equal class representation
Stratification restores equal class representation · slide 34

The demonstrated failure is vivid: an unstratified 3-class split can produce a test set containing zero instances of one class, which makes the reported accuracy meaningless. train_test_split(..., stratify=y) preserves the class proportions in both parts.

Repeated holdout

Repeat the holdout $k$ times and average. The estimate has less variance and is a better estimate of a random test set. Also called Monte Carlo cross-validation.

Repeated holdout
Repeated holdout · slide 38

Bootstrap

Random sampling with replacement, train set size equal to the original dataset size. Draw $n$ times with replacement, then use whatever was never drawn as the test set (about $1-1/e \approx 36.8\%$ of the data).

Bootstrap validation
Bootstrap validation · slide 39

3-way holdout

Train / validation / test. The validation set is "a small subset of the training data, used for internal model evaluation, to get a sense of how the model may perform on an unknown test set".

3-way holdout and the role of the validation set
3-way holdout and the role of the validation set · slide 41

"Why is a validation set necessary? How is it different from the test set?" A validation set exists so that model selection — choosing $k$, $C$, $\gamma$, the number of PCA components — is done on data the model has not been fitted on, while the test set stays untouched until the very end. If you select on the test set, the test set has influenced the model and its reported accuracy is optimistically biased; it is no longer an estimate of generalisation. Concretely: train fits parameters, validation compares candidate hyperparameters/settings, test is used once, for the final unbiased number. In k-fold cross-validation the validation set is replaced by folds, but the test set is still held out.

k-fold cross-validation

> A validation set is no longer needed: the training set is split into $k$ subsets (folds), the model is trained on $k-1$ and validated on the remaining one, rotating. The best model is then used on the test set.

k-fold cross-validation
k-fold cross-validation · slide 43

"Every aspect of the learning method that involves use of data — variable selection, model evaluation, etc. — must be cross-validated." If you scale, impute, select features or choose $k$ outside the CV loop, information leaks from the validation fold into training and your estimate is optimistic. This sentence is worth memorising; it is the standard follow-up question.

Leave-one-out (LOO)

$k$ is set to $n$: $n$ models are evaluated, each trained on $n-1$ samples and validated on 1.

k-foldLOO
Folds$k$ (typically 5 or 10)$n$
Models trained$k$$n$
Training size per fold$(k-1)n/k$$n-1$
Biasslightly pessimistic for small $k$nearly unbiased
Variancelowerhigher — the $n$ training sets differ by only one point, so the models are almost identical and their errors are highly correlated
Cost$k$ fits$n$ fits — prohibitive beyond a few thousand samples
Stratificationpossibletrivially balanced
Leave-one-out
Leave-one-out · slide 45

"What is cross-validation? k-fold vs LOO?" CV estimates generalisation by rotating which part of the data is held out: partition into $k$ folds, train on $k-1$, validate on the held-out fold, repeat so each fold is validation exactly once, then average the $k$ scores. $k$-fold costs $k$ fits and offers a tunable bias-variance trade-off (small $k$ → more pessimistic bias, less variance; large $k$ → less bias, more variance, more cost). LOO is the $k=n$ extreme: $n$ fits, each on $n-1$ samples, so the bias is nearly zero but the $n$ estimates are highly correlated and the variance and compute are large. Choose $k=5$ or $10$ for a single point estimate — the standard advice — and LOO only for very small datasets.

Metrics, restated

Classification: accuracy, confusion matrix, precision, recall, sensitivity, specificity, F1, ROC, AUC. Regression: MSE, RMSE, MAE, percentage error, max error, $R^2$.

Why compute metrics at all
Why compute metrics at all · slide 49

Five reasons given: the training objective is only a proxy; you need a quantitative target; it organises your effort; it measures progress over time; it helps interpret performance.