The learning problem: generalization, bias-variance and regularization

  • Beginner
  • 35 min
  • Lesson 1 of 2 in ML foundations
  • Last verified

Open slides(24 slides)

You will be able to

  • Frame a task as supervised learning, and explain why we minimise empirical risk on training data as a stand-in for expected risk on unseen data.
  • State the job of the train, validation and test sets, and name the leaks that make a reported score too optimistic.
  • Diagnose high bias or high variance from train and validation error and from learning curves, and pick the fix that matches.
  • Explain how an L2 or L1 penalty changes the fitted weights, why only L1 gives exact zeros, and how the strength lambda trades variance for bias.

Concept

This is a common opening topic in machine learning interviews, and every later lesson builds on it. Here is the whole idea in one sentence: learning means fitting the past without memorizing it.

In supervised learning you have examples (xi,yi)(x_i, y_i): inputs (features) and the answers you want (labels). You pick a family of functions fθf_\theta with adjustable parameters θ\theta, and you search for the parameters that make good predictions on inputs the model has never seen.

The catch is in the last clause. You can only measure error on data you have. Think of grading a student on the practice book and hoping the score predicts the exam. So you do something indirect: you minimise the average loss on the training set, called the empirical risk, and hope it tracks the expected risk, the average loss over the real world.

θ^=arg⁡min⁡θ  1n∑i=1nℓ(fθ(xi), yi)  +  λ R(θ)\hat\theta = \arg\min_\theta \; \frac{1}{n}\sum_{i=1}^{n} \ell\big(f_\theta(x_i),\, y_i\big) \;+\; \lambda\, R(\theta)
SymbolMeaning
nnNumber of training examples
fθ(xi)f_\theta(x_i)The model’s prediction for input xix_i
yiy_iThe true label
ℓ\ellLoss: how wrong one prediction is (squared error, log loss)
R(θ)R(\theta)A penalty on model complexity (regularizer)
λ\lambdaHow strongly the penalty counts. You choose it; it is a hyperparameter

The rest of this lesson is about the gap between “low training loss” and “works on new data”, and the tools that manage it.

Diagram: The model makes predictions, the loss scores them, and the optimizer updates the weights in a loop.

no

yes

Data X, y

Model f(x, w)

Loss: how wrong

Optimizer: update w

Evaluate on unseen data

Generalizes?

Fix: data, features,
capacity, regularization

Ship and monitor

Diagram summary: The model makes predictions, the loss scores them, and the optimizer updates the weights in a loop. The decision that matters comes after the loop: only error on unseen data tells you whether the model generalizes, and if it does not, you change data, features, model size or regularization and go round again.

Other learning settings differ in what you have. Supervised learning has inputs and labels (fraud or not, a house price). Unsupervised learning has inputs only (customer clusters). Self-supervised learning builds labels from the data itself (next-token prediction in language models). Reinforcement learning has a reward signal from actions. This course starts with supervised learning because most production ML is supervised, and its ideas carry over.

The common losses (squared error versus absolute error, cross-entropy, hinge) are compared in the next lesson on linear models, loss and optimization. Two vocabulary points that interviewers probe. Parameters (weights) are learned from training data by the optimizer. Hyperparameters (learning rate, tree depth, λ\lambda) are set by you, and you choose them using validation data.

Why It Matters

If minimising training loss were enough, the best model would be a lookup table that memorizes every training example. It would score zero training error and be useless on the first new input.

Generalization is the whole point, and it is where real projects fail. A model with 99% training accuracy and 80% validation accuracy is common, and it is not a success. In production you meet a second version of the problem: the data you train on is a snapshot of the past, and the data you serve is the future. Every tool in this lesson is a way to estimate or improve how a model behaves on data it was not fitted to.

Mental Model

Think of a student preparing for an exam. The training set is the practice book. A student who memorizes the answers to every practice problem gets full marks on the book and fails the exam when the questions change. That is overfitting. A student who only learned “answers are usually B” scores poorly on the book and the exam alike. That is underfitting.

The exam has to be a fresh set of questions, or it measures nothing. That is why we hold data back. And if the student keeps retaking the same mock exam and tweaking their study plan based on the result, the mock exam has become part of the practice book. That is what happens when you tune on the test set.

Splits and leakage

You need three jobs done on three separate pieces of data.

  • Train fits the parameters.
  • Validation chooses hyperparameters and compares models. Each time you look at it and make a decision, it leaks a little information into your choices.
  • Test is used once, at the end, to report an unbiased estimate.

A memory hook: train learns, validation chooses, test judges.

Diagram: The data is split into three disjoint parts.

All data

Train, about 70%
fit weights

Validation, about 15%
tune hyperparameters

Test, about 15%
one final look

Diagram summary: The data is split into three disjoint parts. Train is the largest and fits the weights, validation tunes hyperparameters, and test is held back for one final report. The percentages are a common default, not a rule.

The scikit-learn documentation states the danger directly: when you tweak hyperparameters until the score on the test set is good, “knowledge about the test set can ‘leak’ into the model and evaluation metrics no longer report on generalization performance” (scikit-learn, Cross-validation).

Splitting three ways has a cost: you spend data on evaluation that could have trained the model. With small data, use k-fold cross-validation. Rotate which fold is the validation fold and report the mean and spread. Keep a test set aside anyway. Pick the variant that matches your data:

SituationSplit to useWhy
Imbalanced classesStratified k-foldKeeps the rare class in every fold
Several rows per patient or userGroup k-foldOne entity must not sit on both sides of the split
Data ordered in timeTime-ordered (forward-chaining) splitThe model must not train on the future

The most common leak

Fitting a scaler or imputer on all the data before splitting. The mean and standard deviation of the held-out rows then influence training. The documentation’s rule is that preprocessing “should be learnt from a training set and applied to held-out data”, and a Pipeline does this correctly inside each cross-validation fold (scikit-learn, Cross-validation). Other traps: reporting the best cross-validation score as the final estimate (you chose it because it was the best), and celebrating a high training score.

Bias, variance and learning curves

Two different ways to be wrong explain nearly all generalization failure.

  • Bias is systematic error from a model too simple for the pattern. A straight line fitted to a curve is wrong in the same way on every training sample you draw.
  • Variance is sensitivity to the particular training sample. A very flexible model fitted to a different sample would come out very different, because it is fitting the noise in each one.

For squared error at a point xx, the expected error over random training sets splits into three parts:

E[(y−f^(x))2]=Bias[f^(x)]2⏟systematic error+Var[f^(x)]⏟sensitivity to the sample+σ2⏟irreducible noise\mathbb{E}\big[(y-\hat f(x))^2\big] = \underbrace{\mathrm{Bias}[\hat f(x)]^2}_{\text{systematic error}} + \underbrace{\mathrm{Var}[\hat f(x)]}_{\text{sensitivity to the sample}} + \underbrace{\sigma^2}_{\text{irreducible noise}}

The last term is noise in the labels themselves. No model can remove it, so it is a floor under every error number you see.

Worked example: a degree sweep

The data: y=sin⁡(2πx)+noisey = \sin(2\pi x) + \text{noise} with noise standard deviation 0.3, so the noise variance, the floor, is 0.32=0.090.3^2 = 0.09. There are 15 training points spread over [0,1][0, 1] and 18 random validation points. We fit polynomials of increasing degree by least squares and measure mean squared error (MSE). The full script is in the Code section; it solves the equations in exact fractions, so the numbers are not round-off artefacts (a high-degree fit solved in ordinary floating point can be badly wrong). The scikit-learn gallery shows the same pattern with degrees 1, 4 and 15 on a noisy cosine (scikit-learn, Underfitting vs. Overfitting).

DegreeTrain MSEValidation MSEReading
10.3260.372Bias: both errors are about four times the 0.09 floor
30.0810.121Best validation error, close to the floor
50.0560.215Validation error has started to climb
90.0250.811Variance: train keeps falling, validation is much worse
120.01517.593Variance, extreme: 13 coefficients for 15 points

Training error never rises as you add flexibility, because each polynomial family contains the one before it. Validation error falls, reaches a minimum at degree 3, then climbs. The shape matters more than the exact digits.

One trap: do not read “train error below the noise floor” as proof of overfitting. Any fitted model has training error a little below the floor, because it was fitted to those very points. A least-squares model that is correctly specified, with pp parameters, has expected training MSE of σ2(n−p)/n\sigma^2 (n-p)/n, which would be 0.09×11/15=0.0660.09 \times 11/15 = 0.066 for p=4p = 4 and n=15n = 15 (the textbook name is the optimism of the training error, ESL section 7.4). The signal is on the other side: compare validation error with the floor, and watch the gap between the two.

Is this one seed typical? I repeated the degree sweep over 100 random seeds. Degree 3 beat degree 1 on validation in 98 of them, degree 12 was worse than degree 3 in 96, and the best degree was 3 in 61, 5 in 29 and something else in 10. The median validation MSE rose from 0.112 (degree 3) to 0.535 (degree 12), while the median training MSE fell from 0.068 to 0.013.

Diagram: Moving from degree 1 to degree 3 to degree 12, training error falls at every step (0.326, 0.081, 0.015).

Low complexity
degree 1
train 0.326, validation 0.372

Sweet spot
degree 3
train 0.081, validation 0.121

High complexity
degree 12
train 0.015, validation 17.593

Diagram summary: Moving from degree 1 to degree 3 to degree 12, training error falls at every step (0.326, 0.081, 0.015). Validation error falls first, to 0.121 at degree 3, and then explodes to 17.593 at degree 12. The widening gap between the two numbers is the signature of variance.

Learning curves: will more data help?

A learning curve plots train and validation error against the number of training examples. The picture tells you which problem you have and, crucially, whether collecting data is worth the money. The scikit-learn guide puts it this way: “you should only collect more training data if the true function is too complex to be approximated by an estimator with a lower variance” (scikit-learn, Validation curves).

A second run uses a pool of 60 shuffled training points and 200 validation points (a larger validation set steadies the estimate), a ridge penalty of 10−810^{-8}, and the first nn points of the pool each time. The script is in the Code section.

ModelTrain sizeTrain MSEValidation MSE
Degree 1150.3130.291
Degree 1300.3110.309
Degree 1600.3060.287
Degree 9150.0590.219
Degree 9300.0960.112
Degree 9600.0950.087

The straight line’s two curves sit together at about 0.3, over three times the noise floor, and do not move as data quadruples. More data will not help; it needs more capacity or better features. The degree-9 curves start apart and converge as data grows, so here more data really does help (as would regularization). Validation at n=60n=60 is a little under 0.09 only because 200 validation points are themselves a noisy estimate. Over 20 other seeds the median degree-9 validation MSE at n=15n=15 was 2.464 (the curves can start very far apart) and 0.103 at n=60n=60.

Diagram: Look at training error first.

yes

no

yes

no

Compare train and validation error

Train error high?

High bias, underfit
bigger model, better features,
train longer, less regularization

Validation much higher
than train?

High variance, overfit
more data, regularize, simpler model,
early stopping, augmentation

Good fit
check the test set once

Diagram summary: Look at training error first. If it is high, the model cannot even fit the data it sees, so the problem is bias. If training error is low but validation error is much higher, the problem is variance. If both are low and close, check the test set once. “High” is judged against a baseline or the noise floor, not an absolute number. Training error sits a little below the floor for any fitted model, so compare validation error with the floor.
SymptomDiagnosisWhat helpsWhat does not
Train and validation both high and closeHigh biasRicher model, new features, less regularizationMore data of the same kind
Low train, much higher validationHigh varianceMore data, regularization, simpler model, early stopping, baggingA bigger model

Model capacity and regularization are two knobs on the same trade. Many variance-reducing changes act as regularization.

Regularization

The cheapest way to stop a flexible model from fitting noise is to charge it for large weights. Large weights are what let a curve wiggle through every point. The two standard charges are the L2 and L1 norms of the weights.

L2 (ridge): shrink smoothly

Add λ∥w∥22\lambda\lVert w\rVert_2^2 to the loss. For linear regression this gives a closed form:

w^=(X⊤X+λI)−1X⊤y\hat w = (X^{\top}X + \lambda I)^{-1} X^{\top} y

Adding λI\lambda I also makes X⊤XX^{\top}X safely invertible when features are nearly collinear. Without it, the least-squares estimate is, in the scikit-learn documentation’s words, “highly sensitive to random errors in the observed target, producing a large variance” (scikit-learn, Linear models). Ridge is a good default, especially with many correlated features.

L1 (lasso): shrink and select

Add λ∥w∥1\lambda\lVert w\rVert_1 instead. Lasso “is able to set coefficients exactly to zero” (scikit-learn, Linear models), so it doubles as feature selection. The original paper explains that the constraint on the sum of absolute coefficients “tends to produce some coefficients that are exactly 0” (Tibshirani, 1996).

Why exact zeros? A worked one-feature example

Use one feature with no intercept and three points: x=[1,2,3]x = [1, 2, 3], y=[2,4,5]y = [2, 4, 5]. Then ∑xy=25\sum xy = 25 and ∑x2=14\sum x^2 = 14. Ordinary least squares gives w=25/14=1.786w = 25/14 = 1.786.

With the loss ∑(y−wx)2+λw2\sum (y - wx)^2 + \lambda w^2 (ridge), setting the derivative to zero gives:

wridge=∑xy∑x2+λw_{\text{ridge}} = \frac{\sum xy}{\sum x^2 + \lambda}

With the loss 12∑(y−wx)2+λ∣w∣\tfrac12\sum (y - wx)^2 + \lambda\lvert w\rvert (lasso), the derivative gives, while ww stays positive:

wlasso=max⁡ ⁣(∑xy−λ,  0)∑x2w_{\text{lasso}} = \frac{\max\!\big(\sum xy - \lambda,\; 0\big)}{\sum x^2}
λ\lambdaRidge wwLasso ww
01.7861.786
71.1901.286
140.8930.786
250.6410.000
1400.1620.000

Read the table for the mechanism. Ridge divides the weight by a bigger number: it shrinks in proportion to the weight and approaches zero but never arrives, even at λ=140\lambda = 140. Lasso subtracts a fixed amount: once λ\lambda reaches ∑xy=25\sum xy = 25 the weight is exactly zero and stays there. In gradient terms, the L2 penalty pushes back with force proportional to ww (weak on small weights), while the L1 penalty pushes with constant force regardless of size. Geometrically, the L1 constraint region is a diamond with corners on the axes, and the loss contour tends to touch a corner, where some weights are zero; the L2 region is a disc with no corners.

The two losses are scaled differently (one has a factor of one half), so compare the shapes of the columns, not the strength of one row against the other.

The price: bias

Regularization is not free. On the same three points the unregularized fit has training MSE 0.119. Ridge with λ=14\lambda = 14 halves the weight, and the training MSE becomes 3.839. That is the trade: you accept a worse fit to the training data in return for a model less sensitive to the sample. Too much λ\lambda underfits. You choose λ\lambda on validation data, never on the test set.

The same effect on the degree-12 polynomial from the sweep above (the penalty is on the coefficients of powers of the rescaled xx, not the intercept):

LambdaTrain MSEValidation MSE
0.000000010.01517.593
0.010.0490.326
0.10.0620.181
10.1920.220
100.5220.506

Training error rises with every step. Validation error falls from 17.6 to its minimum of 0.181 at λ=0.1\lambda = 0.1, then climbs again as the model underfits. Choose λ\lambda at that minimum, on validation data. With the penalty tuned, the degree-12 polynomial goes from 17.593 to 0.181, a huge improvement, though on this draw it still does not beat the plain cubic’s 0.121.

L2 (ridge)L1 (lasso)
Penaltyλ∑wj2\lambda\sum w_j^2λ∑∣wj∣\lambda\sum \lvert w_j\rvert
EffectShrinks all weights smoothlyDrives some weights to exactly 0
Bayesian readingGaussian prior on the weightsLaplace prior on the weights (the lasso is the posterior mode)
Best whenMany correlated features, default choiceYou want a sparse, selected model
WeaknessKeeps every featureWith correlated features, picks one arbitrarily

Elastic net mixes both penalties. The scikit-learn documentation says it is useful when several features are correlated: “Lasso is likely to pick one of these at random, while elastic-net is likely to pick both” (scikit-learn, Linear models). The Bayesian reading comes from the shape of the penalty: a Gaussian prior on a weight has a negative log proportional to w2w^2, and a Laplace prior has one proportional to ∣w∣\lvert w\rvert. Tibshirani (1996) noted that the lasso is the posterior mode under independent Laplace priors, as Park and Casella (2008) restate. Other ways to control variance are early stopping (halt when validation loss stops improving), data augmentation, a smaller model and more data; dropout and weight decay for neural networks come in the deep learning module.

Standardize features before an L1 or L2 penalty. (The polynomial script instead rescales xx to [−1,1][-1, 1], which keeps every power on a comparable scale.) The penalty adds up the sizes of the weights, and a weight’s size depends on the feature’s units. A feature measured in metres is penalized differently from the same feature in millimetres. Fit the scaler on the training data only.

Libraries also scale the penalty differently. scikit-learn’s Ridge minimises ∥Xw−y∥22+α∥w∥22\lVert Xw-y\rVert_2^2 + \alpha\lVert w\rVert_2^2, while Lasso uses 12n∥Xw−y∥22+α∥w∥1\tfrac{1}{2n}\lVert Xw-y\rVert_2^2 + \alpha\lVert w\rVert_1. The same alpha is not the same strength across them (scikit-learn, Linear models).

Code

This standard-library script produced every number in the degree sweep, the lambda table and the learning curves. It uses exact fractions, so it needs no installs and has no round-off. The numbers were checked with Python 3.14; they rely on random.Random(0) and random.Random(1000), so another Python version could draw different noise. If your printed values differ in the last digit or more, the shape (validation minimum at a moderate degree, explosion at high degree) should still hold.

Python

import math
import random
from fractions import Fraction as Fr


def solve(A, b):
    """Gaussian elimination in exact fractions, so there is no round-off."""
    n = len(A)
    M = [row[:] + [b[i]] for i, row in enumerate(A)]
    for c in range(n):
        p = next(r for r in range(c, n) if M[r][c] != 0)
        M[c], M[p] = M[p], M[c]
        for r in range(c + 1, n):
            f = M[r][c] / M[c][c]
            for k in range(c, n + 1):
                M[r][k] -= f * M[c][k]
    w = [Fr(0)] * n
    for i in range(n - 1, -1, -1):
        w[i] = (M[i][n] - sum(M[i][k] * w[k] for k in range(i + 1, n))) / M[i][i]
    return w


def basis(x, degree):
    t = Fr(x) * 2 - 1                      # rescale x from [0, 1] to [-1, 1]
    return [t ** j for j in range(degree + 1)]


def fit(xs, ys, degree, lam):
    """Ridge-penalised polynomial fit; the intercept is not penalised."""
    rows = [basis(x, degree) for x in xs]
    p = degree + 1
    A = [[sum(r[i] * r[j] for r in rows) + (Fr(lam) if i == j and i > 0 else 0)
          for j in range(p)] for i in range(p)]
    b = [sum(r[i] * Fr(y) for r, y in zip(rows, ys)) for i in range(p)]
    return solve(A, b)


def mse(w, xs, ys):
    pred = lambda x: float(sum(a * b for a, b in zip(w, basis(x, len(w) - 1))))
    return sum((pred(x) - y) ** 2 for x, y in zip(xs, ys)) / len(xs)


def noisy_sine(x, rng):
    return math.sin(2 * math.pi * x) + rng.gauss(0, 0.3)


rng = random.Random(0)
xt = [(i + rng.random()) / 15 for i in range(15)]      # 15 training points, spread over [0, 1]
yt = [noisy_sine(x, rng) for x in xt]
xv = [rng.random() for _ in range(18)]                 # 18 validation points
yv = [noisy_sine(x, rng) for x in xv]

print("degree sweep, lambda = 1e-8")
for d in (1, 3, 5, 9, 12):
    w = fit(xt, yt, d, 1e-8)
    print(d, round(mse(w, xt, yt), 3), round(mse(w, xv, yv), 3))

print("degree 12, lambda sweep")
for lam in (1e-8, 1e-2, 1e-1, 1, 10):
    w = fit(xt, yt, 12, lam)
    print(lam, round(mse(w, xt, yt), 3), round(mse(w, xv, yv), 3))

print("learning curves, lambda = 1e-8, 200 validation points")
rng = random.Random(1000)
pool = [(i + rng.random()) / 60 for i in range(60)]
rng.shuffle(pool)
ypool = [noisy_sine(x, rng) for x in pool]
xv2 = [rng.random() for _ in range(200)]
yv2 = [noisy_sine(x, rng) for x in xv2]
for d in (1, 9):
    for n in (15, 30, 60):
        w = fit(pool[:n], ypool[:n], d, 1e-8)
        print(d, n, round(mse(w, pool[:n], ypool[:n]), 3), round(mse(w, xv2, yv2), 3))

What to look for: at degree 12, raising lambda should shrink the gap between train and validation error. At degree 1 it would not help, because that model has a bias problem, not a variance problem. In scikit-learn the equivalent is make_pipeline(PolynomialFeatures(d), StandardScaler(), Ridge(alpha=...)), which refits the scaler on training rows only.

Real-World Application

On a real project the checklist runs in this order. First, rule out a split bug or leakage: a model that is suspiciously good on training data and poor on validation can mean overfitting, but it can also mean the validation set does not resemble production. Then compare against a simple baseline. Then read the learning curves to decide where to spend the next week: data collection for a variance problem, feature work for a bias problem.

A concrete case: a model scores 99% on training and 80% on validation. Fix order: check for leaks and a mismatched validation set, then add data or regularization, reduce complexity, use early stopping or augmentation, and confirm that validation looks like production traffic. More data does not rescue a high-bias model, and it does not rescue noisy labels or a training distribution that differs from serving.

Interview Perspective

Expect “explain bias-variance and how you diagnose each”, “why does L1 give sparse weights”, “train 99%, validation 80%: what do you do”, and “when would more data not help”. A strong answer follows a pattern: one-line definition, the picture, the formula or mechanism, when it fails, and a real example. The weak answer lists regularizers without saying which problem each solves.

Provenance: Common industry pattern. These are standard fundamentals for ML roles, not a verified list for any named company.

Practice Questions

  • Basic: What is the difference between a parameter and a hyperparameter? Give an example of each.
  • Intermediate: Training error is 2% and validation error is 25%. Diagnose it and give three fixes.
  • Advanced: Why do the penalty gradients explain L1 sparsity but L2 shrinkage?
  • Product-Company: A teammate tunes five hyperparameters by looking at the test score and reports the best one. What is wrong, and what do you change?

Activity

Fit the one-feature example from the Regularization section by hand: compute the ridge and lasso weights for λ=10\lambda = 10 and for λ=50\lambda = 50, then say which of the two ever reaches exactly zero and why. Then sketch the learning curves you would expect for a straight line fitted to curved data and for a degree-15 polynomial, and mark the noise floor.

Homework

Implement ridge and lasso for a single feature, a validation-error function, a bias-or-variance diagnosis rule, and a lambda search. The code is in homework/; run the tests until they pass.

Quick Revision

  • Learning = minimise empirical risk (training loss) as a proxy for expected risk on unseen data.
  • Train fits, validation chooses, test judges once. Fit every scaler inside the training fold.
  • Error = bias squared + variance + irreducible noise. High train error means bias; low train error with a big validation gap means variance.
  • Learning curves show whether more data helps (variance: yes; bias: no).
  • L2 shrinks all weights in proportion; L1 subtracts a constant and reaches exact zero. Too much lambda underfits. Standardize first.

Check yourself

  • Walk-through: Without notes, explain what you check, in order, when train accuracy is 99% and validation accuracy is 80%.
  • Variation: The same gap appears after you double the training set and it shrinks only a little. What does that tell you?
  • Common misconception: “More data fixes everything”, and “regularization always improves the model”.

Resources & Further Reading

Checked sources to go deeper. The essential ones come first in each group.

Hands-on

More for this module: ML foundations resources

Practice

Test what you just read. Quizzes and cards are grouped by module: ML foundations.

Check yourself12 questions on what this lesson set out to teach

Checking answers needs JavaScript. You can still read every question and option below.

0 of 12 answered

Keyboard: arrow keys move between options. Space or Enter selects the focused option.

ObjectiveFrame a task as supervised learning, and explain why we minimise empirical risk on training data as a stand-in for expected risk on unseen data.

  1. Question 1 of 12A model is trained by minimising the average loss on the training set. What is that quantity a stand-in for?

    Choose one answer.

  2. Question 2 of 12Which of these tasks is supervised learning?

    Choose one answer.

  3. Question 3 of 12During training, loss on the training set keeps falling for 50 epochs, but loss on the validation set bottoms out at epoch 10 and then rises. A teammate says the model is still improving. What is the best reply?

    Choose one answer.

ObjectiveState the job of the train, validation and test sets, and name the leaks that make a reported score too optimistic.

  1. Question 4 of 12You compared 200 model configurations on the same validation set, and the best one scores 0.92 there. What should you expect on a fresh test set?

    Choose one answer.

  2. Question 5 of 12Which of these are data leaks that make a validation score look better than production performance? Select all that apply.

    Choose all that apply.

  3. Question 6 of 12You have 400 labelled rows. Splitting 70/15/15 leaves only about 60 rows for validation and the scores swing a lot between random splits. What is the most sensible change?

    Choose one answer.

ObjectiveDiagnose high bias or high variance from train and validation error and from learning curves, and pick the fix that matches.

  1. Question 7 of 12A model has training MSE 0.30 and validation MSE 0.29, while the estimated label-noise variance is 0.09. What do you conclude?

    Choose one answer.

  2. Question 8 of 12Training accuracy is 99% and validation accuracy is 80%. After checking for leakage and a mismatched validation set, which actions fit a high-variance diagnosis? Select all that apply.

    Choose all that apply.

  3. Question 9 of 12A straight-line model's train and validation curves have both flattened at about the same high error, about 0.3 against a noise floor of 0.09, as the training set grows from 15 to 60 rows. A manager asks you to buy ten times more labelled data. What do you say?

    Choose one answer.

ObjectiveExplain how an L2 or L1 penalty changes the fitted weights, why only L1 gives exact zeros, and how the strength lambda trades variance for bias.

  1. Question 10 of 12On the lesson's data (x = 1, 2, 3 and y = 2, 4, 5, with sum of xy 25 and sum of x squared 14), what weight does the lasso loss give at lambda = 30?

    Choose one answer.

  2. Question 11 of 12You standardize features and fit lasso and ridge on 200 features, most of them irrelevant. What is the typical difference in the fitted weights?

    Choose one answer.

  3. Question 12 of 12Ridge is fitted to the degree-12 polynomial at four lambdas. (lambda, train MSE, validation MSE): (0.01, 0.049, 0.326), (0.1, 0.062, 0.181), (1, 0.192, 0.220), (10, 0.522, 0.506). Which lambda do you pick, and why?

    Choose one answer.