ECE571 / Week 11 · Regularization

Week 11 · Regularization

Regularization

A model with too much freedom memorizes its training data. Regularization keeps all the features but charges the model for large weights, so it has to earn every bit of complexity it uses.

~35 min read 10 practice questions + 2 problems Reading: Géron Ch. 4 ("Learning Curves", "Regularized Linear Models"), Ch. 11 ("Avoiding Overfitting")
The big picture

Week 2 showed the failure mode: a flexible model can drive its training error to zero and still predict new data badly (overfitting). This lecture is about the most widely used cure. Instead of minimizing the loss alone, we minimize loss + λ × (size of the weights). The extra term, the regularizer, depends only on the model, never on the data, and the number sets how much we care about it. Measure size with the squared L2 norm and you get ridge regression (weights shrink smoothly, and the "weight decay" update in gradient descent). Measure it with the L1 norm and you get the lasso (many weights become exactly zero, so it also selects features). The same idea appears in the SVM's from week 5, in logistic regression, and in neural networks, where dropout, data augmentation and early stopping join the toolbox.

After this you can
Section 1

Overfitting and three fixes

Lecture 00:02–00:20, 03:20–05:18, 09:54–13:46Slides 3, 5–9Géron Ch. 4, "Learning Curves", "The Bias/Variance Trade-off"

Slides 6 and 7 show the picture from week 2 three times over: a model that is too simple (underfitting), one that is about right, and one that is too flexible (overfitting). In the language of the bias/variance trade-off:

UnderfitGood fitOverfit
Example (slide 6)degree 4 through every point
Training errorhighlow≈ 0
Error on new datahighlowhigh
Bias / variancehigh biasbalancedlow bias, high variance

Bias is error from wrong assumptions (a line can't follow a curve). Variance is sensitivity to the particular training sample (a wiggly curve changes completely if you move one point). Overfitting is most likely when there are many features or parameters and few examples. The professor's example is 100 features with only a handful of houses (slide 8).

λ = 0train 0.00 · val 2.56 λ = 10⁻⁵train 0.14 · val 0.24 λ = 10train 0.62 · val 0.65
The same degree-9 polynomial, fit to the same 10 points, with three amounts of regularization. Dots are the training data; the dashed curve is the true function the data came from. With (left) the curve passes through every point (training RMSE 0.00) but swings wildly between them (validation RMSE 2.56; the curve leaves the box at both ends). A tiny penalty (middle) gives a smooth curve close to the truth. A large penalty (right) flattens it into a near-line: underfitting. All numbers computed with the regularized normal equation of Section 4.

The lecture lists three ways to fight overfitting (11:00–12:44 and slide 9):

  1. Get more training data. More points pin the curve down. In deep learning, when real data is scarce, you manufacture more by data augmentation (Section 8).
  2. Use fewer features. Pick the useful ones by hand, use a model-selection algorithm, or compress them with PCA (week 10's dimension reduction).
  3. Regularize. Keep all the features, but shrink the size of the parameters. This works well when there are many features that each contribute a little to predicting .
How the professor frames it (12:25–12:44)

"PCA is trying to reduce the dimensionality. Regularization is trying to squeeze, or narrow down, your feasible space for your model." Regularization doesn't remove any feature; it limits how large the weights may become, so the model can't build the extreme combinations that produce wild curves.

Slide 3 gives a second reason, specific to deep networks: regularization helps "avoid NaN for extreme weights". If weights are free to grow without bound, activations and gradients can overflow to infinity and then to NaN (not-a-number). A small L2 penalty keeps them in a sane range (Section 8).

A model scores 99% on training data and 70% on validation data. Which regularization change would you try first?

That's a big train/validation gap, the signature of overfitting (high variance). Increase the regularization strength (or get more data, or use fewer features). Decreasing would make it worse.

Section 2

The regularized cost function

Lecture 00:20–03:20, 13:46–18:58Slides 2, 10, 12–14Géron Ch. 4, "Ridge Regression"; Bishop §1.1, §3.1.4

Intuition first (slide 10). Suppose the degree-4 model below overfits, and we suspect the culprits are and :

Add a big charge for them to the thing we minimize:

Any sizeable or now costs far more than it could save in squared error, so the minimizer makes them nearly zero. The fitted curve becomes essentially quadratic, which is the good fit. The professor's summary (14:43): a larger coefficient on a parameter's square forces that parameter to be smaller.

In practice we don't know which parameters are the culprits, so we penalize all of them (except the intercept). Small parameters give a "simpler", smoother hypothesis that is less prone to overfitting (slide 12). The general form (slide 2) is

and for linear regression with the L2 regularizer (slides 13–14):

number of training examples
number of features; parameters are
the model's prediction; for linear regression (with )
regularization parameter: how much small weights matter compared with fitting the data
the regularizer, ; the sum starts at
Don't regularize the bias θ₀

The sum starts at (the professor's note on slide 12: "bias, don't regularize bias"). only shifts the curve up or down; shrinking it toward 0 would drag every prediction toward 0 for no gain in smoothness. Géron says the same: "the bias term is not regularized".

The two extremes of λ (17:38–18:58):

  • : the penalty disappears and we're back to plain least squares, overfitting included (left panel above).
  • huge (slide 14 asks about ): any nonzero costs enormously, so all of them go to ≈ 0. The model becomes , a flat line at the mean of the 's. "Not a good model": severe underfitting.
  • In between, is a hyperparameter that trades fit against simplicity. You tune it on validation data (Section 7).
Worked example: the degree-9 fits from Section 1

10 training points from (noise standard deviation 0.25), features . Validation error is measured on 51 fresh points. RMSE = root mean squared error.

λtrain RMSEvalidation RMSElargest |θⱼ|
00.0002.556848,000
10⁻⁶0.1380.24945.0
10⁻⁵0.1430.24121.2
10⁻⁴0.1460.24215.6
0.0010.1860.2898.8
0.010.2580.3693.0
0.10.3270.4101.2
10.4770.5260.541
100.6220.6480.122

Read it top to bottom. Training error only goes up as grows (the model is more constrained). Validation error falls from 2.56 to about 0.24 and then rises again. The weights tell the story: the unregularized fit needs coefficients near 850,000 that cancel each other to thread through every point, and even cuts them to 45.

Heads up: slide 2 notation

Slide 2 writes and with as the number of weights, then uses as the number of examples in on the same slide. In the rest of the deck (and here), = examples and = features, so those sums run to . Also note that "L2 regularization" uses the squared L2 norm, , not .

With and data whose -values average 4, what does the fitted regression line look like?

All slopes are crushed to ≈ 0, and (unpenalized) takes the value that minimizes squared error for a constant model: the mean. So it's the horizontal line . The worked example in Section 4 shows this happening step by step.

Section 3

Gradient descent: weight decay

Lecture 19:00–21:06Slides 16–17Géron Ch. 4, "Ridge Regression"; Bishop §3.1.4

Differentiate . The squared-error part gives the familiar gradient from week 3. The penalty adds , but only for :

One gradient-descent step with learning rate , regrouped (slide 17, bottom line):

and is updated exactly as before, with no shrink factor.

This is the "key difference" the professor stresses (19:40–21:06): every step first shrinks each weight by the factor , then takes the ordinary least-squares step. The factor is a little below 1 (the slide's handwritten note: "≈ 0.99"). Because weights decay geometrically toward zero unless the data keeps pushing them up, L2 regularization is also called weight decay (Bishop §3.1.4).

Heads up: slide 17's handwritten term has the wrong sign

Inside the bracket, the annotation writes

It must be : the derivative of is . With a minus sign, the step would grow the weights. The printed line at the bottom of slide 17, with the factor , is correct, and slide 22 prints .

Worked example: weight decay in action

Data: , , so . Model . Take , . The shrink factor is .

Start at the unregularized least-squares answer . There, the squared-error gradient is exactly zero, so the only force is the shrink:

  1. Step 1. (no loss gradient, no shrink). .
  2. Step 2. Predictions ; residuals . Loss gradients: and . So and .
  3. Keep going. The slope shrinks, the intercept rises to compensate, and the iterates settle at , the point where the shrink and the data's pull balance. Section 4 gets this same answer in one line.
stepθ₀θ₁
00.50001.4000
10.50001.3650
20.50881.3571
30.51861.3532
∞1.08331.1667
With , and , what is the shrink factor? What happens if ?

. If the factor is negative, so each step flips the weight's sign. That's a sign the learning rate (or ) is far too big; with sensible values the factor is just below 1, as the slide's note says.

Section 4

The normal equation with λ

Lecture 21:06–22:16Slides 18–19Géron Ch. 4, Eq. 4-9; Bishop §3.1.4, Eq. 3.28

Stack the examples as rows of (with a leading column of 1s) and the targets in , as in week 3. In matrix form,

where is the identity with a 0 in the top-left corner (so is not penalized). Setting the gradient to zero:

With this is week 3's normal equation. The term is the entire effect of L2 regularization.

Worked example: shrinkage on four points

Same data as Section 3: , . With one feature, the matrix formula reduces to two short ones. Let , , , . Then

λθ₀θ₁ (slope)prediction at x = 5sum of squared errors
00.5001.4007.5000.200
11.0831.1676.9170.472
52.2500.7005.7502.650
203.3000.2804.7006.472
→ ∞4.00004.00010.000

The slope shrinks smoothly toward 0 but never reaches it for any finite . The training error rises as the price. In the limit we get slide 14's flat line at . The row matches where gradient descent converged in Section 3.

0123400.511.5θ₀ (intercept)θ₁ (slope)λ = 0λ = 1λ = 5λ = 20λ → ∞
Ridge pulls the solution from the least-squares point toward "no slope", along a path, as λ grows. The ellipses are contours of the squared error in the plane, drawn through the solutions. Each larger accepts a worse contour (more error) in exchange for a smaller slope. Here the path happens to be a straight line, , because the unpenalized intercept always re-centers the line on .

The bonus: invertibility

Week 3's formula needs to be invertible. Slide 19 points out when it isn't: if there are no more examples than features (), the matrix has rank at most , so it is singular. The same happens with duplicated or perfectly correlated features. The professor calls this an ill-posed problem (21:30): infinitely many fit equally well, and the formula breaks.

For any , is always invertible. Proof sketch: for any nonzero ,

The second term is positive unless , and then , so the first is positive. A positive-definite matrix is invertible.

Worked example: duplicated feature

Two identical features, no intercept: rows , . Then

The determinant is 0: any fits perfectly, so there is no unique answer. With :

Ridge picks the solution that splits the weight evenly between the twins. As it approaches , the smallest-norm exact fit.

Cross-check with the textbook: where λ's scale goes

Different sources scale the penalty differently, so "" means different things. The slides use , whose solution is . Bishop (Eq. 3.27–3.28) uses : same formula. scikit-learn's Ridge(alpha) minimizes : again the same, so alpha = the slides' . Géron writes the cost as (Eq. 4-8) but gives the closed form (Eq. 4-9). Those two only agree if the in 4-9 is from 4-8; the closed form is the one that matches scikit-learn. When you compare numbers across sources, check the scaling first.

Heads up: lecture 21:19

The lecture calls "the covariance matrix". It's only proportional to the feature covariance matrix when the features are centered (mean 0), and then you divide by . The point being made still holds: when this matrix is low-rank, inverting it is ill-posed, and adding fixes that.

You have 50 examples and 200 features. Can you use the plain normal equation? The ridge one?

Plain: no. , so (201 × 201) has rank at most 50 and is singular. Ridge: yes, for any , is invertible.

Section 5

L1 vs L2: why lasso gives zeros

Lecture 01:08–03:20, 05:18–09:54, 12:44–13:28Slides 2, 4Géron Ch. 4, "Lasso Regression", "Elastic Net", Fig. 4-19; Bishop §3.1.4, Fig. 3.4

Slide 2 offers two ways to measure the size of the weights:

To see how they differ, rewrite "minimize loss + λ·penalty" in an equivalent constrained form: minimize the loss alone, but only over weights inside a region, or . Each corresponds to some budget (Bishop §3.1.4, via Lagrange multipliers): larger λ ↔ smaller region (12:44). The region is the professor's "feasible space". In 2-D, the L2 region is a disk and the L1 region is a diamond (a square turned 45°, which the lecture calls "the square").

L1: diamondw₁w₂w*ŵsparse: w₂ = 0 exactly L2: diskw₁w₂w*ŵboth weights nonzero
The growing loss contours first touch the diamond at a corner, where one weight is exactly zero; they touch the disk at a generic point. Same loss in both panels: elliptical contours around the unregularized optimum . Imagine the ellipses growing outward from until one first touches the shaded region; that touching point is the regularized solution. L1 (left): . L2 (right): , both nonzero. This redraws slide 4 from exact solutions with a budget of 1.

Why corners win: the diamond sticks out furthest exactly at its corners, which lie on the axes. An ellipse coming in from a random direction is much more likely to hit a corner than a flat edge. In dimensions the L1 ball has corners and edges on every axis and coordinate plane, so many coordinates end up exactly 0. The disk has no corners: the touching point is almost never on an axis, so ridge weights are small but nonzero "with high probability" (09:02).

Flagged in lecture · 07:22 and 28:47

"From this geometry perspective, you should remember, you should understand: if you add L1 regularization to your problem, the solution you get will be sparse." And in the closing summary: "L1 regularization gives you a sparse representation or sparse model. L2 regularization gives a non-sparse model." Be ready to draw the diamond and the disk and explain the corner argument.

Watching weights as λ grows

Ridge (L2)024log₁₀ λ →-202w₁w₂w₃w₄ Lasso (L1)024log₁₀ λ →-202w₁w₂w₃w₄
Ridge shrinks every weight smoothly toward 0; lasso drops them to exactly 0, one at a time. Simulated data: 60 examples, 4 standardized features, true weights , with feature 4 correlated with feature 1. Left of each plot is almost no regularization (weights ≈ least squares: 3.03, −2.03, 0.62, 0.03). In the lasso plot, the useless is zeroed first (around ), then (), and the important features last. In the ridge plot nothing is ever exactly zero (and even grows for a while, because it can stand in for its correlated partner once is shrunk).
Worked example: lasso hits exactly zero, ridge doesn't

Back to the four points (, ), now with the L1 cost . After the intercept absorbs the means, the slope minimizes

  1. If : set the derivative to 0: This is only valid while it's positive, i.e. .
  2. If : at the slope of the squared-error part is , and the kink of can absorb any slope up to in size. So exactly is the minimum.
  3. Compare to ridge: , which is never 0.
λ04101420
Lasso θ₁1.4001.0000.40000
Ridge θ₁1.4000.7780.4670.3680.280

The L1 penalty's slope is a constant all the way down to 0, so it keeps pushing a small weight just as hard as a big one, and the weight snaps to 0. The L2 penalty's slope fades as shrinks, so the push dies out before reaching 0.

Training a lasso. has no derivative at 0, but gradient descent still works if you use the subgradient (with sign(0) = 0) in place of the derivative (Géron Eq. 4-11). The step size has to shrink over time, or the weights bounce around zero instead of settling there.

Elastic net: both at once

The lecture (02:12–03:03) mentions using L1 and L2 together, called elastic net. Géron's version mixes them with a ratio :

is lasso, is ridge.

L2 (ridge)L1 (lasso)Elastic net
Penaltya mix of both
Regiondisk / balldiamond (corners on axes)rounded diamond
Weightsall shrunk, none exactly 0many exactly 0 (sparse)some exactly 0
Closed form?yes (Section 4)no; subgradient or coordinate descentno
Use whengood default; many small effectsyou suspect few features matterlike lasso, but with correlated features or , where lasso can behave erratically
A model with 1,000 features is trained with lasso and ends with 37 nonzero weights. What has the lasso done besides regularizing?

Feature selection: it decided 963 features aren't worth their penalty and removed them from the model entirely. Ridge would have kept all 1,000 with small weights.

Section 6

Regularized logistic regression

Lecture 16:51–17:05, 22:16–22:48Slides 7, 20–23Géron Ch. 4, "Logistic Regression" (p. 147 on C)

Logistic regression (week 3's classifier, ) overfits the same way: with many polynomial features the decision boundary curls around individual points (slides 7 and 21). The fix is the same penalty added to the log loss (slide 21):

Its gradient has exactly the same form as for linear regression, because the log loss's derivative works out to (the week 3 result). Only is different. So the update is the same shrink-then-step rule:

The professor leaves the derivation as an exercise ("this is the calculation you can go through by yourself", 22:44). Problem 2 at the end walks through it.

λ ≈ 0 (C = 10⁴)train 100% · test 82% λ = 1 (C = 1)train 92% · test 89%
Regularizing a logistic classifier smooths its decision boundary. 60 points (one class inside a ring of the other), degree-8 polynomial features. Nearly unregularized (left), the boundary bends around individual points, even enclosing a hole, and gets 100% on the training set but only 82% on 2,000 new points. With (right) the boundary is a smooth loop: 92% train, 89% test. Fitted with scikit-learn, whose C is .
Heads up: slide 23 has a sign error, and a misplaced parenthesis

Slide 23 (the "advanced optimization" cost function) writes gradient(2) as

and likewise for . It must be , as on slide 22. Its also reads "", which should be . (gradient(1), for , correctly has no term.)

Cross-check with the textbook: scikit-learn uses C, not λ

Géron notes that scikit-learn's LogisticRegression controls regularization with C, the inverse of the strength: higher C = less regularization, the same direction as the SVM's C in week 5. It also applies an L2 penalty by default.

Why does the professor say "the only thing that changes" for logistic regression is ?

Because the gradient of the log loss, , has the same form as the squared-error gradient, and the penalty's gradient doesn't depend on the loss at all. Swap in the sigmoid for and the update rule is identical.

Section 7

Choosing λ

Lecture 18:24–18:58, 28:47–30:02Slide 14Géron Ch. 4, "Ridge Regression" (scaling note)

is a hyperparameter, so you can't pick it by minimizing training error: that always says . Use held-out data, exactly as in week 2. "How to define the lambda parameter: we can use cross-validation to select lambda" (29:53).

  1. Pick a grid on a log scale, for example .
  2. For each , train on the training folds and measure error on the validation fold (or a single validation set). Measure it without the penalty term: the penalty is only for training (Géron).
  3. Pick the with the lowest validation error, retrain on all training data with it, and report test error once.
-15-12-9-6-3000.250.50.751log₁₀ λ (more regularization →)RMSEvalidationtrainingbest λoverfitunderfit
Training error always rises with λ; validation error is U-shaped, and its bottom is the λ to use. The degree-9 example from Sections 1–2, scanned over from to . On the left the model overfits (validation error runs off the top of the chart toward 2.56); on the right it underfits. The minimum, about 0.24, is near . (These tiny values are because is tiny on ; the useful range depends on the scale of your features.)
Scale your features first

The penalty treats every the same, but a feature measured in large units only needs a small weight, so it barely gets penalized, while a feature in small units needs a large weight and gets crushed. Standardize features (mean 0, standard deviation 1) before ridge or lasso. Géron: "It is important to scale the data … before performing Ridge Regression … This is true of most regularized models."

Your validation error is lowest at the largest λ in your grid. What should you do?

Extend the grid to larger values. The true minimum may be beyond the edge you searched. The same applies at the small end.

Section 8

Regularization in deep learning

Lecture 22:48–28:44Slides 24–27Géron Ch. 11, "Avoiding Overfitting Through Regularization"; Ch. 4, "Early Stopping"; Bishop §5.5.2

Neural networks come later in the course, but the professor previews four regularizers. Networks have huge numbers of parameters, often more than training examples, so they need all the help they can get.

1. L2 penalty (weight decay)

Slide 25 adds the same penalty, summed over every layer's weight matrix :

and backpropagation gets one extra term per layer:

It's the same weight decay as Section 3.

Heads up: slide 25 "then we apply sqrt"

Slide 25 says to stack each weight matrix into one vector "and then we apply sqrt(w1² + w2² …)". The penalty is the squared norm, , with no square root (that's the squared Frobenius norm). The slide's own gradient is the derivative of ; with the square root, it would be different.

The lecture says here is usually very small, around to (23:03), and that it helps when training blows up to NaN. Treat the exact value as problem-dependent: Géron's Keras example uses 0.01. Tune it like any hyperparameter.

2. Dropout

The correct description (Géron Ch. 11, slide 26): at every training step, each neuron (in the chosen layers, never the output layer) is independently "dropped" with probability , the dropout rate. A dropped neuron outputs 0 for that step, for both the forward pass and the backward pass, so the weights attached to it get no gradient that step. The next step draws a fresh random set. At test time nothing is dropped.

Training stepdropped units output 0 Test timeevery unit on, no dropout
Each training step trains a different random sub-network; the test-time network uses everything. Crossed-out units are dropped for this step only, along with all their connections. With droppable units there are possible sub-networks, so the final network behaves like an average of a huge ensemble that shares weights (Géron).

Why it works. No neuron can rely on a particular partner being present, so each has to be useful on its own, and no single weight can dominate (the slide's handwritten note: "not a single weight dominates"). Géron's analogy: a company whose employees flip a coin each morning to decide whether to come in would have to spread every critical skill across several people.

Worked example: inverted dropout

A layer outputs . Dropout rate , so the keep probability is . This step's random mask is .

Inverted dropout (slide 26's "most common technique") multiplies by the mask and divides by the keep probability during training: .

Why divide? Each unit survives half the time, so on average its output is , the same as without dropout. That keeps the next layer's input on the same scale at train and test time, so at test time you just use the network as is.

Heads up: lecture 23:50–26:05 describes dropout incorrectly

The lecture describes dropout as choosing some weights to leave "unchanged" (not updated) during the forward pass, then choosing a different random set for backpropagation. That isn't dropout. The slide itself says the random dropout vector "is used for forward and back propagation and is the same for them, but it is different for each iteration". Dropout zeroes neurons' outputs (not individual weights; dropping individual weights is a different method called DropConnect), and the same mask is used for the forward and backward pass of a step. Also, slide 26 says the probability is "≪ 1"; typical dropout rates are 10% to 50% (Géron), so not tiny.

3. Data augmentation

The first fix for overfitting is more data. When you can't collect more, make more from what you have: for images, shifted, rotated, flipped or rescaled copies are new training examples with the same label (26:13–27:05). Slide 27 shows Bishop's illustration: the same degree-9 polynomial that overfits 15 points is smooth with 100 points. Only use transformations that don't change the label (a flipped "6" is a "9").

4. Early stopping

Train with gradient descent and watch the validation error after every epoch. Training error keeps falling, but validation error falls, bottoms out and then climbs as the model starts fitting noise. Stop at the validation minimum, even though training error is still decreasing (27:05–28:04). Géron quotes Geoffrey Hinton calling it a "beautiful free lunch".

0501001502002503000123epoch (one full-batch gradient step each)RMSEstop here (epoch 37)overfitting zonevalidationtraining
Validation error bottoms out at epoch 37 and then rises while training error keeps falling. Linear regression with 40 features but only 30 training examples (only 5 features actually matter), trained by full-batch gradient descent from . Validation RMSE drops from 3.04 to 2.12 at epoch 37, then climbs to 2.85 by epoch 300 as training RMSE heads to 0.07. Stopping at epoch 37 keeps the best model.
  • In practice, save the weights each time validation error hits a new low, keep training for a while ("patience"), then roll back to the best saved weights. With mini-batch training the curve is noisy, so you can't stop at the first uptick (Géron).
  • Validation data, not k-fold. The lecture says the stopping point is usually found "using cross-validation" (28:04). In practice it's a held-out validation set monitored during training. You can use k-fold to pick the number of epochs, but that means training k models.
  • Why it's regularization. Starting from small weights, gradient descent grows them gradually, so stopping early keeps them small. For a quadratic loss, Bishop (§5.5.2) shows early stopping behaves like weight decay, with (iterations × learning rate) playing the role of . That's the "probabilistic" explanation the professor alludes to at 28:16.
In the early-stopping figure, what would plain "train until the training loss stops improving" have given you?

The epoch-300 model: training RMSE 0.07 but validation RMSE 2.85, worse than the 2.12 available at epoch 37. Training loss alone can't tell you when you've started overfitting.

Section 9

Cheat sheet

Regularized costloss (data) + · regularizer (model only)
Ridge / L2; never penalize
Lasso / L1penalty ; sparse weights, feature selection
Elastic net
λ extremes: plain fit (overfit risk); : flat line (underfit)
GD (weight decay) for ; same for logistic
Normal equation, ; invertible for any
One featureridge ; lasso ;
Geometrylarger λ ↔ smaller region; L1 diamond → corners → zeros; L2 disk → no zeros
Choosing λlog grid + validation / cross-validation; scale features first
Library knobsRidge(alpha): alpha = λ; LogisticRegression(C): C = 1/λ
Deep nets; dropout (train only, inverted: divide by keep prob); data augmentation; early stopping at validation minimum
Section 10

Practice

Score: 0 / 0

Q1Why does the regularization sum start at instead of ?

Q2Regularized linear regression with (slide 14) produces:

Q3Gradient descent with , , . Each step multiplies () by what before the usual gradient step?

Q4One feature, centered data with and . The least-squares slope is 1.5. What is the ridge slope with ?

Q5Same data (, ) with the L1 cost . What is the smallest that makes the lasso slope exactly 0?

Q6Geometrically, why does L1 regularization give sparse solutions?

Q7You have examples and features. Which is true?

Q8For regularized logistic regression, is (writing for , and the sum over examples):

Q9You scan . Training errors: 0.10, 0.14, 0.22, 0.40. Validation errors: 0.52, 0.31, 0.29, 0.43. Which do you pick?

Q10Inverted dropout with dropout rate . A unit that survives this training step would have output 2.0. What does it pass on?

Problem 1: For , , find (a) the least-squares line, (b) the ridge line with , (c) the lasso line with , and (d) the smallest for which the lasso slope is 0. (Use the slides' scaling; the intercept is not penalized.)

Means: , . Centered : ; centered : .

. .

(a) , . Line .

(b) , . Line .

(c) , . Line .

(d) The slope is 0 once , so . The line is then . Ridge would need to get there.

Checked numerically: the regularized normal equation gives (1.4, 0.4); a direct minimization of the L1 cost gives (1.55, 0.3) at λ = 5 and slope 0 at λ = 8.

Problem 2: Derive the gradient-descent update for L2-regularized logistic regression (the "calculation you can go through by yourself", 22:44), and show it has the shrink-then-step form.

Let and . A useful fact:

One example's loss is . By the chain rule,

Average over the examples and add the derivative of , which is :

Then regroups as

For there is no penalty, so its update has no shrink factor. This is identical to the linear-regression rule; only differs.