2.2.13 · D4Linear & Logistic Regression

Exercises — L1 (Lasso) regularization

2,446 words11 min readBack to topic

If any symbol here is unfamiliar, everything is defined in L1 (Lasso) regularization. See also Ridge (L2) Regularization, Elastic Net, and the algorithms Coordinate Descent and Proximal Gradient (ISTA/FISTA).


Level 1 — Recognition

Exercise 1.1

Which of these penalties makes weights exactly zero, and which only shrinks them? (a) (b) (c)

Recall Solution
  • (a) is the L1 / Lasso penalty — the sum of absolute values. Its constraint region is a diamond with corners on the axes, so it produces exact zeros.
  • (b) is the L2 / Ridge penalty — sum of squares. Its region is a smooth circle: weights shrink but never hit exactly zero (unless already zero).
  • (c) is Elastic Net: the L1 part still supplies the corner, so it can produce zeros, while the L2 part keeps correlated features grouped.

Exercise 1.2

State the soft-threshold value for , — and identify which of the three cases (positive, negative, clamped) applies.

Recall Solution

Here and , so we are in the positive case: shrink by .


Level 2 — Application

Exercise 2.1

OLS (ordinary least squares) gives and . Apply soft-thresholding to each coordinate. Which features survive?

Recall Solution

Why coordinate-by-coordinate works here. "Orthonormal features" means the feature columns are perpendicular unit vectors, so the data-fit term splits into a clean sum with no cross-terms: , where is the OLS coefficient for feature . Add the L1 penalty and the whole cost becomes a sum over — each term depends only on its own . Minimizing a sum of independent one-variable problems is the same as minimizing each separately, and each is exactly the soft-threshold. That is why coordinates decouple.

Apply per coordinate:

  • (dropped: )
  • (dropped: )

Result . Features 1 and 4 survive; 2 and 3 are eliminated. Note the boundary case : since we need strictly, it clamps to zero.

Exercise 2.2

For a single orthonormal coordinate with , compare the Lasso weight and the Ridge weight when . Ridge minimizes .

Recall Solution

Lasso: . Ridge derivative, step by step. We minimize by setting .

  • The is placed there on purpose: differentiating uses the power rule (bring the exponent down) and chain rule (times the inside derivative ), giving . The and the cancel — that is why we write the , to get a clean derivative.
  • Differentiating likewise brings the exponent down: .
  • So .

Lasso subtracts a constant (); Ridge multiplies by a constant factor (). Neither is zero here, but only Lasso could reach zero (if ).


Level 3 — Analysis

Exercise 3.1

For fixed (single coordinate), sketch/derive the Lasso weight as ranges over . At what does the feature die?

Recall Solution

(since ).

  • For : , a straight line decreasing with slope .
  • At : .
  • For : stays at .

The feature dies exactly at .

Reading the figure below (s01): the horizontal axis is the penalty strength (from to ); the vertical axis is the resulting Lasso weight . The magenta curve starts at when (no penalty ⇒ full OLS value), slides down as a straight ramp of slope (violet arrow), hits zero at the orange dot where , and then stays flat on the axis. This ramp-then-flat shape is the "regularization path" for one feature.

Figure — L1 (Lasso) regularization

Exercise 3.2

Explain geometrically why the ellipse of MSE (mean squared error) contours meeting the L1 diamond gives a zero, but meeting the L2 circle usually does not. Reference the corner.

Recall Solution

Minimizing MSE subject to a budget means: expand the elliptical MSE contours (centered at the OLS solution) outward until they first touch the constraint region.

  • The L1 diamond has sharp corners sitting on the axes. A corner sticks out, so an incoming ellipse overwhelmingly touches it there first — and a corner has one coordinate . That coordinate is dropped.
  • The L2 circle is smooth: no corner sticks out, so the first touch is at a generic point where both coordinates are nonzero. Zero-touching is a measure-zero coincidence.

Reading the figure below (s02): both axes are the two weights, (horizontal) and (vertical). The magenta diamond has four corners exactly on the axes; the violet dashed circle is the L2 budget of the same size. The orange dot up-and-right is the OLS solution, and the faint orange rings around it are MSE level sets (contours of equal error — each ring is a set of weight pairs giving the same training error, growing outward). Watch which shape the smallest ring reaches first: it lands on the magenta diamond corner (marked, where ), not on a smooth side. That single touch is why a coordinate becomes exactly zero under L1.

Figure — L1 (Lasso) regularization

Level 4 — Synthesis

Exercise 4.1

A dataset has two nearly-identical (correlated) features. Lasso keeps feature A and zeros feature B on one train/test split; on another split it keeps B and zeros A. (a) Why? (b) Which method fixes it, and how?

Recall Solution

(a) Two correlated features carry almost the same information. The L1 penalty pays a "tax" per unit of coefficient magnitude regardless of feature, so putting all the weight on one feature costs the same as splitting it — but concentrating on one lets the other drop to zero (a corner), which the diamond geometry prefers. Which of the twins wins is decided by tiny sampling noise, so it flips between splits ⇒ instability. (b) Elastic Net: add an L2 term, minimizing . The L2 part is smooth and prefers to spread weight across correlated features (it penalizes large individual weights quadratically), so the twins get similar nonzero weights and are kept together and stably. This is the grouping effect.

Exercise 4.2

You standardize features before Lasso. Show numerically why skipping standardization changes which feature gets dropped. Feature in meters has OLS weight ; the same feature in millimeters has OLS weight . With , which version survives?

Recall Solution

Scaling a feature by (meters → millimeters) divides its coefficient by : .

  • Meters: survives.
  • Millimeters: dropped.

The same feature is kept or dropped depending only on its units! The L1 penalty treats all coefficients equally, so a differently-scaled coefficient is penalized differently. Standardize (zero mean, unit variance) so every feature faces the same effective tax.


Level 5 — Mastery

Exercise 5.1

Solve one full coordinate-descent update for Lasso by hand, without assuming orthonormality. For coordinate , the update minimizes over with all others fixed: Given for coordinate : , , . Compute the new .

Recall Solution

This is the Coordinate Descent update: it isolates one coordinate, treats the rest as fixed, and solves a one-dimensional Lasso problem — which is exactly soft-thresholding, then rescaled by . WHY the ? is a raw correlation; dividing by normalizes it into a coefficient scale. The soft-threshold is applied on the correlation scale (numerator), which is why the non-orthonormal case still reduces to .

Exercise 5.2

For L1-logistic regression, one proximal-gradient (ISTA) step is: take a gradient step on the smooth logistic loss to get , then apply (with step size ). Suppose after the gradient step a coordinate has value , step , . Give the updated weight.

Recall Solution

Proximal Gradient (ISTA/FISTA) splits the objective into smooth (logistic loss, differentiable) + non-smooth (L1). It gradient-steps the smooth part, then applies the L1 proximal operator, which is soft-thresholding with threshold . Threshold . The sign is preserved, the magnitude shrunk by the threshold — same mechanism as linear Lasso, because the L1 term is independent of which loss (MSE or logistic) it is attached to.

Exercise 5.3

Synthesis check. As you sweep from upward with fixed (orthonormal), list the order in which features die and the exact at each death.

Recall Solution

A feature dies when (the shrink amount finally cancels its magnitude):

  • Feature 2 () dies first at .
  • Feature 3 () dies at .
  • Feature 1 () dies last at .

Death order = increasing : the smallest-signal feature drops first. This is the "regularization path," and where to stop along it is chosen by Cross-Validation — trading bias against variance.


Active Recall

Recall At what

does an orthonormal feature with OLS coefficient die? Exactly at — the point where the shrink amount equals the coefficient's magnitude.

Recall Why does the coordinate-descent update still reduce to soft-thresholding without orthonormality?

Each coordinate's 1-D subproblem is a soft-threshold on the correlation , rescaled by : .

Recall What is

and what does give? , and : a coefficient already at zero stays at zero.