Lesson 3.5core3 h 30 min⚡ live demo

Evaluating models: metrics, validation and the bias–variance trade-off

How good is it, compared to what, and how sure are you?

Choosing the metric, the validation protocol and the error bars is where most real projects are won or lost — a model that looks 97% accurate can be useless, and a 0.5% improvement can be noise. This lesson gives you the vocabulary of the confusion matrix, the ROC and precision–recall curves, the discipline of cross-validation without leakage, and the bias–variance decomposition that explains why models fail. The same ideas evaluate LLMs (8.7 Evaluating LLMs), RAG systems (9.8 Evaluating and observing LLM apps) and agents (10.9 Evaluating agents).

You'll be able to

  • Compute accuracy, precision, recall, F1, specificity and balanced accuracy from a confusion matrix and explain the accuracy paradox
  • Read and choose between ROC and precision–recall curves, and interpret AUC as a ranking probability
  • Select a validation protocol (holdout, k-fold, stratified, grouped, time-series, nested) and name the leakage each prevents
  • Derive the bias–variance decomposition of expected squared error and use it to diagnose underfitting and overfitting
  • Read learning curves and decide whether more data, more capacity or more regularization is the fix
  • Attach a standard error to an accuracy and decide whether two models actually differ

Key ideas

  1. A metric is a decision tool: choose one whose change would change what you do, and state what it misses.
  2. From the confusion matrix: precision = TP/(TP+FP), recall = TP/(TP+FN), F1 = harmonic mean; accuracy misleads under imbalance (the accuracy paradox).
  3. ROC/AUC measures ranking quality (P(score⁺ > score⁻)) independent of threshold; prefer precision–recall curves when positives are rare.
Show 5 more key ideas
  1. Set thresholds by expected cost, not 0.5; evaluate probabilities themselves with log loss/Brier and calibration plots.
  2. k-fold CV gives a mean and a spread; stratify for imbalance, group by entity, split by time for temporal data, nest for honest hyperparameter search; the test set is used once.
  3. Expected squared error = Bias² + Variance + irreducible noise; capacity lowers bias and raises variance, giving the U-shaped test error.
  4. Learning curves tell you whether the fix is capacity (both errors high) or data/regularization (persistent gap).
  5. Accuracy has standard error √(p(1−p)/n); compare models with paired bootstrap or repeated CV, and treat differences within the spread as noise.

Suggested path through this lesson