What is learning? ERM, generalization and the ML workflow
The one idea every model in this path is a special case of
Linear regression, gradient-boosted trees, GPT and a diffusion model all do the same thing: pick a function from a family to make a loss small on data, in the hope that it stays small on data they have not seen. That hope has a name — generalization — and a mathematics that explains when it is justified. Learn this framing once and the rest of the path becomes a catalogue of choices for the hypothesis space, the loss and the optimizer (3.2 Linear regression, 4.1 From perceptron to MLP; universal approximation, 7.6 Decoder-only: GPT and autoregressive generation).
You'll be able to
- Define a learning problem by its task, experience and performance measure, and classify it as supervised, unsupervised, self-supervised or reinforcement learning
- Write down true risk, empirical risk and the ERM principle, and explain why minimizing training error is not the same as learning
- Decompose excess error into approximation and estimation error and connect them to underfitting and overfitting
- Explain the roles of training, validation and test splits and why the test set is touched once
- State the no-free-lunch idea and give the inductive bias of three model families
- Run the ML workflow from problem framing to a monitored deployment, baseline first
Key ideas
- A learning problem is a triple (task, experience, performance measure); write it down before coding.
- ERM: choose the hypothesis that minimizes average training loss; true risk is the expected loss on new data and is what we actually want.
- Training error is optimistically biased because the model was selected using it; the generalization gap grows with hypothesis-space complexity and shrinks like 1/√n.
Show 4 more key ideas
- Excess error = approximation error (hypothesis space too small → underfitting) + estimation error (too large for the data → overfitting).
- Train fits, validation selects, test is touched once; information must never flow from validation/test into training.
- No free lunch: no algorithm is best on all problems; learning works when the model's inductive bias matches the data's structure.
- Workflow: frame → split → explore → baseline → iterate one change at a time → evaluate with error bars → ship and monitor drift.
Suggested path through this lesson
A definition you can compute with
Tom Mitchell's definition is still the sharpest: a program learns from experience with respect to a task and performance measure if its performance on , measured by , improves with . Every learning problem you will meet can be written as a triple. Spam filtering: = label emails, = labelled emails, = fraction correctly labelled. A language model: = predict the next token, = trillions of tokens of text, = cross-entropy on held-out text (7.6 Decoder-only: GPT and autoregressive generation). An agent: = complete tasks with tools, = trajectories with rewards, = success rate (10.9 Evaluating agents). Writing the triple down before coding is the fastest way to notice that the performance measure you can compute is not the one you care about — the central tension of evaluation (3.5 Evaluating models: metrics, validation and the bias–variance trade-off, 8.7 Evaluating LLMs).
Four kinds of learning
The boundaries blur in practice — a language model is trained with self-supervision, then fine-tuned with supervision, then shaped with reinforcement learning (8.1 The LLM lifecycle and model landscape) — but the vocabulary stays.
Hypothesis space, loss and empirical risk
Fix a hypothesis space : the set of functions the model can represent (all lines; all depth-5 trees; all transformers with a given architecture and weights ). Fix a loss that scores one prediction: squared error , 0–1 loss , cross-entropy (1.9 Information theory: entropy, cross-entropy and KL divergence, 4.3 Loss functions catalog). Assume the data are drawn independently and identically distributed (i.i.d.) from an unknown distribution over . What we want to minimize is the true risk (expected loss on new data):
We cannot compute it because we do not know . What we can compute on a training set is the empirical risk, the average training loss:
Empirical risk minimization (ERM) chooses . Fitting a line by least squares, training a network with gradient descent, growing a tree greedily — all are ERM or approximations of it. The whole question of machine learning is: when is close to ?
Why training error lies, and by how much
For one fixed function , the law of large numbers (1.8 Statistics essentials) says as grows: the training loss is an unbiased, concentrating estimate of the true loss. But is not fixed — it was chosen to make small, so it is optimistically biased on the very data that selected it. The generalization gap is the price of that selection. Statistical learning theory bounds it: with high probability, for every at once,
where "complexity" is a measure of how many distinct behaviours can exhibit on points (the VC dimension or Rademacher complexity — roughly, how many parameters, or how wiggly). The shape of the bound is what matters: the gap grows with the richness of the hypothesis space and shrinks like with data. Memorizing this shape explains most of the trade-offs that follow.
Intuition. A test set works because it is data the selection never saw: on it, is a fixed function, so the law of large numbers applies and the test error is an honest estimate with standard error (3.5 Evaluating models: metrics, validation and the bias–variance trade-off). Use it to choose a model and it stops being honest.
Approximation versus estimation
Let over all functions (the Bayes error — irreducible noise) and the best function in your family. The excess risk of what you actually get splits into two pieces:
Approximation error is the fault of the hypothesis space being too small — a line cannot fit a parabola — and shows up as underfitting: high training and test error. Estimation error is the fault of finite data letting you pick a bad member of a large family — overfitting: low training error, high test error. Making bigger lowers the first and raises the second; this is the bias–variance trade-off, derived precisely in 3.5 Evaluating models: metrics, validation and the bias–variance trade-off and managed in 3.6 Regularization and generalization. Fit degree-1 and degree-15 polynomials to ten noisy points from a sine curve and you see both failure modes in one picture: the line misses the curve everywhere, the degree-15 polynomial passes through every point and swings wildly between them.
Splits: train, validation, test
Because the training error is optimistic and the test set must stay untouched, model development uses three disjoint sets. Train fits parameters. Validation (or k-fold cross-validation, 3.5 Evaluating models: metrics, validation and the bias–variance trade-off) compares models and hyperparameters — degree of the polynomial, in kNN, learning rate. Test is evaluated once, at the end, to report a number. Choosing among 200 hyperparameter settings on the validation set is itself a form of fitting, so the validation score of the winner is slightly optimistic too; the test set is what protects you. Information must never flow backwards: no scaling statistics computed on all data, no duplicates across splits, no features that encode the answer, no future data in a time-series training set (2.3 pandas, data wrangling and plotting, 3.13 Feature engineering, data quality and data-centric ML).
No free lunch and inductive bias
Averaged over all possible data-generating functions, every learning algorithm has the same expected test error — the no-free-lunch theorem. Learning only works because the real world is not an arbitrary function: it has regularities, and a model learns precisely to the extent that its assumptions, its inductive bias, match them. kNN assumes nearby inputs have similar outputs (smoothness, 3.4 k-Nearest Neighbors). Linear models assume additive effects. Trees assume axis-aligned, piecewise-constant structure (3.8 Decision trees). CNNs assume translation equivariance and locality (5.1 Convolution: the operation and its math). Transformers assume little and compensate with data (7.1 Attention Is All You Need: the big picture). There is no universally best model; there is a best model for data with a given structure, found by trying candidates under honest validation.
The workflow
- Frame. Write the triple; decide what a useful result looks like and what a model would replace.
- Data. Collect, split first, then explore the training split (2.3 pandas, data wrangling and plotting).
- Baseline. Predict the mean or majority class; then the simplest sensible model. Everything later must beat this honestly.
- Iterate. Feature engineering, model families, hyperparameters — one change at a time, tracked (2.5 Tooling: Git, GPUs, experiments and the Hugging Face Hub).
- Evaluate. Validation metrics with error bars; error analysis on the worst mistakes; a single test-set evaluation.
- Ship and monitor. Data drifts; the i.i.d. assumption dies the moment the world changes. Monitoring is part of the model.
Where this shows up later
- Every loss in 4.3 Loss functions catalog is an here; every architecture in Phases 4–7 is a choice of ; every optimizer in 4.5 Optimizers and learning-rate schedules is a way to do ERM.
- The generalization gap is measured by validation protocols in 3.5 Evaluating models: metrics, validation and the bias–variance trade-off and shrunk by regularization in 3.6 Regularization and generalization and 4.7 Regularization in deep nets.
- Self-supervised ERM on text is the pretraining objective of LLMs — 7.6 Decoder-only: GPT and autoregressive generation, 8.1 The LLM lifecycle and model landscape; the i.i.d. assumption breaking is distribution shift — 5.9 Interpretability, robustness and adversarial examples, 8.12 Safety, risks and responsible AI.
- Choosing the performance measure you can compute versus the one you care about is the entire topic of LLM and agent evaluation — 8.7 Evaluating LLMs, 10.9 Evaluating agents.
Common pitfalls (5)
- Reporting training accuracy as if it measured learning; it measures memorization capacity.
- Using the test set repeatedly to pick models — it quietly becomes a validation set and the final number is inflated.
- Exploring or preprocessing on the full dataset before splitting, which leaks test statistics into training.
- Skipping the trivial baseline, so a 'good' model is never shown to beat predicting the majority class.
- Assuming i.i.d. data when the deployment distribution differs from the training distribution (time, geography, population).
Recap: all 7 key points
- A learning problem is a triple (task, experience, performance measure); write it down before coding.
- ERM: choose the hypothesis that minimizes average training loss; true risk is the expected loss on new data and is what we actually want.
- Training error is optimistically biased because the model was selected using it; the generalization gap grows with hypothesis-space complexity and shrinks like 1/√n.
- Excess error = approximation error (hypothesis space too small → underfitting) + estimation error (too large for the data → overfitting).
- Train fits, validation selects, test is touched once; information must never flow from validation/test into training.
- No free lunch: no algorithm is best on all problems; learning works when the model's inductive bias matches the data's structure.
- Workflow: frame → split → explore → baseline → iterate one change at a time → evaluate with error bars → ship and monitor drift.
Watch

The classic course opener: what ML is, supervised vs unsupervised vs RL, and the course map. Embedding is disabled; opens on YouTube.
The owner disabled playback on other sites, so this one opens on YouTube.
Read
Exercises
- Write five (T, E, P) triples
For spam filtering, house-price prediction, product recommendation, next-token prediction and a coding agent, write the task, the experience and the performance measure. For each, name one way the computable differs from what you actually care about. Expected: at least two of the five have an obvious gap (e.g., click-through vs long-term satisfaction).
- See the gap
Sample 10 points from , , on . Fit polynomials of degree 1, 3, 9 with
numpy.polyfit, and plot each with the true curve and 1,000 fresh test points. Compute train and test MSE per degree. Expected: train MSE falls monotonically with degree; test MSE is U-shaped with a minimum near degree 3. - Baseline first
On any Kaggle tabular dataset, compute the majority-class (or mean) baseline on a validation split, then train a logistic/linear regression. Report both numbers. Expected: you can state in one sentence how much the model adds over the baseline, with the standard error next to it.
- Find the leak
Take a dataset with a date column and a target that depends on time. Compare a random 80/20 split with a chronological split (train on the past, test on the future). Expected: the random split reports an optimistic score; explain in two sentences which number you would trust in deployment.
Quiz
Flashcards
These cards are now in your spaced-repetition queue. Review all due cards →