Unit 7 · ML & applied AI · Lesson 3 of 13
Baselines, bias-variance, regularization and optimization
Step 1: Learn the ideas
- Baselines: constant, heuristic, linear and tree models
- Bias-variance decomposition and learning curves
- Capacity, overfitting and double descent (awareness)
- L1 and L2 regularization and weight decay
- Early stopping, dropout and data augmentation
- Loss functions and the assumptions they encode
- Gradient descent, learning rate and conditioning
- Stochastic gradients, mini-batches and convexity
Why it matters
Questions such as "your model overfits, what do you do?" or "why does your deep model lose to logistic regression?" test whether you reason from evidence or from habit. Strong answers start from a baseline, read the gap between training and validation error, change one thing, and predict the effect before running it.
Core ideas
Baselines first. Predict the majority class or the mean, then a simple heuristic, then a linear model or gradient-boosted trees on the same features. Baselines calibrate what "good" means, expose pipeline bugs (a deep model that cannot beat the mean is broken, not unlucky) and often ship: on tabular data a well-tuned linear or tree model is a serious competitor. For LLM features the baseline is often a carefully written prompt, or a non-ML rule.
Bias and variance. For squared loss, expected test error over random training sets decomposes into bias^2 + variance + irreducible noise. Operationally, high training error means underfitting (high bias): add capacity or features, train longer, regularize less. Low training error with a large validation gap means overfitting (high variance): add data, regularize, augment, simplify. Learning curves, error against training-set size, show whether more data will help: if validation error is still falling, it will. Large neural networks complicate the classical U-shaped picture (double descent, implicit regularization from SGD), but the train-validation gap remains the operational signal.
Regularization as capacity control.
- L2 (
lambda * ||w||^2) shrinks all weights smoothly; it is MAP with a Gaussian prior and stabilizes collinear features. - L1 (
lambda * ||w||_1) drives some weights exactly to zero, giving sparse models; among correlated features it tends to keep one somewhat arbitrarily. - Weight decay shrinks weights by a constant factor each step. It equals L2 for plain SGD but not for adaptive optimizers such as Adam, which is why AdamW decouples it.
- Early stopping limits how far parameters move from initialization; choose the stopping point on validation data.
- Dropout zeroes random activations during training to discourage co-adapted features; it is switched off at inference, and inverted dropout rescales during training so nothing changes at test time.
- Data augmentation encodes invariances you believe in (crops, flips, paraphrases). Augmentations that change the label, or copies that land in both splits, hurt.
Objectives. The loss encodes what errors cost. Squared error targets the conditional mean and punishes large misses heavily; absolute error targets the median and is robust to outliers; Huber blends the two. Cross-entropy trains probabilities. Ranking tasks use pairwise or listwise losses. Class weights or resampling change the effective class prior, which shifts predicted probabilities and therefore calibration.
Optimization. Gradient descent updates w <- w - eta * grad L(w). Too large a learning rate oscillates or diverges; too small stalls. On ill-conditioned problems the stable step size is set by the steepest direction, so progress along flat directions is slow; feature standardization, normalization layers, momentum and adaptive methods all help. Mini-batch gradients are noisy but unbiased estimates of the full gradient. Linear and logistic regression are convex, so every local optimum is global; neural network losses are not, but in practice learning rate, conditioning and initialization matter more than bad local minima.
Common misconceptions
- "Start with the most powerful model." Without a baseline you cannot tell whether it helps or whether the pipeline is broken.
- "Regularization always improves validation scores." It trades variance for bias; if the model already underfits, regularization makes it worse.
- "L2 regularization and weight decay are the same." Only under plain SGD; under Adam they differ, hence AdamW.
- "More data fixes everything." It reduces variance, not bias, label noise or a mismatch between training and deployment data.
- "Dropout stays on at inference." Standard practice turns it off; keeping it on (Monte Carlo dropout) is a deliberate technique for uncertainty estimates.
- "Training fails because of bad local minima." Usually the learning rate, conditioning, initialization or a bug is responsible.
How to approach it
Rehearse a fixed diagnostic script: baseline, training error, validation gap, learning curve, then one targeted change. Derive the bias-variance decomposition once by hand. Fit L1 and L2 logistic regression across strengths and plot coefficient paths. Train a small network with and without dropout and augmentation and compare curves, predicting them first. Graduate-level interviews expect the vocabulary and the diagnosis; mid and senior levels expect remedies chosen under data and compute constraints, plus what you would measure.
Suggested order
- 1Read CS229 main notes Ch. 8 (Generalization), including the bias-variance decomposition and the double descent section.
- 2Read CS229 main notes Ch. 9 (Regularization and model selection) for explicit and implicit regularization and model selection via cross-validation.
- 3Read D2L 3.6 (Generalization), 3.7 (Weight Decay) and 5.6 (Dropout), running the code cells.
- 4Read Deep Learning Ch. 7 (Regularization for Deep Learning), sections on parameter norm penalties, dataset augmentation, early stopping and dropout.
- 5Read Rules of ML #1 to #4 on launching without ML, designing metrics first and keeping the first model simple.
- 6Do the baseline and regularization experiments in the practice guidance, writing down your prediction before each run.
Step 2: Check off what you can do
Tap each one you can genuinely do or explain. Each earns 10 XP.
Step 3: Go deeper
Stanford CS229 Machine LearningStart here
Stanford UniversitySection: Main notes: Ch. 8 (Generalization) and Ch. 9 (Regularization and model selection)
Bias-variance decomposition, double descent, regularization and model selection at derivation level.
Open(opens in a new tab)Link responded, 5 Oct 2026Dive into Deep Learning
d2l.ai (open-source book)Section: 3.6. Generalization
Runnable introduction to generalization and model selection; continue with 3.7 Weight Decay and 5.6 Dropout.
Open(opens in a new tab)Link responded, 5 Oct 2026Deep LearningStart here
MIT Press (free online edition at deeplearningbook.org)Section: Ch. 7: Regularization for Deep Learning
Reference treatment of norm penalties, augmentation, early stopping and dropout as regularizers.
Open(opens in a new tab)Link responded, 5 Oct 2026Rules of Machine Learning: Best Practices for ML Engineering
Google for DevelopersSection: Before Machine Learning and ML Phase I (Rules #1 to #4)
The practitioner case for heuristics, metrics first and a simple first model as the baseline.
Open(opens in a new tab)Link responded, 5 Oct 2026
Step 4: Practice
(1) On a tabular dataset, compare a majority-class predictor, logistic regression and gradient-boosted trees under the same cross-validation, and explain each gap. (2) Plot learning curves for a deliberately underfitting and a deliberately overfitting model and state the remedy each needs. (3) Fit L1- and L2-regularized logistic regression across a range of strengths, plot coefficient paths, and check which of two correlated features L1 keeps. (4) Train a small network with and without dropout, augmentation and early stopping; predict the curves before each run and note where you were wrong.
No external problems are linked; follow the guidance above.
Record attempts on each problem’s page (+15 XP, +10 more when solved on your own).
Step 5: Test yourself
Answer each one out loud or on paper before you finish the lesson.
- Question 1Training and validation error are both high and close together. What do you try first, and what do you avoid?
- Question 2Why does L1 produce exact zeros while L2 does not?
- Question 3When does data augmentation hurt?
- Question 4Your deep model loses to logistic regression on a tabular task. Give three explanations.
- Question 5What happens to gradient descent on an ill-conditioned quadratic, and what helps?
- Question 6Why is early stopping a form of regularization?
You’re done when you can
- Explain the bias-variance tradeoff with a learning-curve sketch and prescribe remedies for each regime in under three minutes.
- Derive the bias-variance decomposition for squared loss without notes.
- Explain why L2 regularization and weight decay differ under Adam.
- Choose a loss for three described tasks and justify each in one sentence.
Finish the lesson
Unlocks next: Metrics, calibration, thresholds and uncertainty, Neural networks, backpropagation and numerical stability, Optimization and math foundations for ML research


