DS701 Session 8 — Wed Sep 30, 2026
State the “supervised contract” — the assumption the lecture says makes it possible for a rule learned on training data to say anything about data it has never seen — and give one concrete situation in which the contract is broken.
In the polynomial curve-fitting example, the training error reaches zero at \(k = 9\) while the test error is smallest at \(k = 3\). Explain why training error can only go down (never up) as \(k\) increases, and why that makes it useless for choosing \(k\). Then say which of bias and variance the \(k = 9\) model suffers from, and which the \(k = 1\) model — in one sentence each.
You have 200 labelled rows and must choose the maximum depth of a decision tree (a hyperparameter). Describe how you would use 5-fold cross-validation to choose it, and say what role — if any — the test set plays in that choice. Why is 5-fold CV preferable to a single random train/validation split when the data is this small?
Given training pairs \(\{(\mathbf{x}_i, y_i)\}_{i=1}^N\), learn a rule that predicts \(y_j\) for an \(\mathbf{x}_j\) not in the training data.
Two assumptions make that tractable:
Two consequences we will lean on all term:


\(N = 10\) points, \(y = \sin(2\pi x) + \varepsilon\). Least squares finds the \(\mathbf{w}^*\) that minimises training error \(E(\mathbf{w}) = \sum_n [f(x_n, \mathbf{w}) - y_n]^2\). Training error: \(1.91 \to 1.45 \to 0.64 \to\) 0.00 at \(k = 9\) (10 coefficients, 10 points — it interpolates). Which one would you bet on for the next point?

Why it happens: too many parameters for the data; a model more complex than the phenomenon. What helps: more data, less complexity (hyperparameters), regularization.

Bias — the model is too simple to capture the pattern; it underfits (\(k = 0, 1\)). Refit it on new data and it is wrong the same way every time.
Variance — the model is so flexible it fits the noise; it overfits (\(k = 9\)). Refit it on a different sample from the same distribution and you get a very different answer.
Both are defined over repeated draws of the training set — which is exactly what you will do in Part 3 today.

Same trade-off, different knob, every week from now on: tree depth, \(k\) in \(k\)-NN, the regularization strength, early stopping in neural nets.

train_test_split puts a random half aside.Random, not first-half/second-half — a systematic split breaks the i.i.d. contract between the two halves.

The full protocol: lock away a test set → choose the hyperparameter by CV on the rest → refit on all training data → score the test set once. That last number is the only one you may report.
The plots so far vary the model at fixed data. Today’s stretch holds the model fixed and varies the amount of data:
High bias (a line on a cubic)
High variance (degree 12 on 10 points)
Learn to read the two signatures, then diagnose a mystery model from its curve alone and prescribe the fix: more data, a simpler model, or a more flexible one.
Goal: on your section’s synthetic regression, reproduce the train-vs-test curve for degrees 0–12 and pick the degree; pick it again with 5-fold CV without touching the test set; measure bias and variance for \(k = 1\) vs \(k = 9\) by refitting on many samples; then draw learning curves for an under-fit and an over-fit model and diagnose a mystery model from its curve.
numpy, matplotlib, scikit-learn.The activity notebook goes live on the day of the lecture. Colab is optional — you can also open it on GitHub and run it locally.
Full lecture notes: Generalization: Why Training Error Lies
Wed Oct 7, in class — closed notes, paper and pencil, covering lectures 01–07 (foundations + clustering + today).