Skip to content
mlmentorship

L1 versus L2: derive the zero coefficient

Solve a common quadratic under absolute and squared penalties, test the zero subgradient condition, and separate objective sparsity from solver behavior.

Published · 6 min read ·Core ·Mixed

ML breadth · active recall

Practice before you read

8 minutes. Explain the mechanism, why it works, when it fails, and one alternative.

ML breadth · closed-book attempt

L1 versus L2: derive the zero coefficient

Explain the mechanism, why it works, when it fails, and one alternative.

Problem

Context. Fit $a=(2,0.3)$ using data loss $L_{data}(w)=\frac12\lVert w-a\rVert_2^2$ and coefficient $\lambda=0.5$. Compare L1 penalty $\lambda\sum_i|w_i|$ with half-scaled L2 penalty $\frac\lambda2\sum_iw_i^2$. Task. Derive the minimizing coefficients for each penalized objective and identify which coefficients become exactly zero. Explain how changing the penalty convention or feature scaling changes the comparison. Constraints. Coordinates are independent, feature units are comparable, and no intercept appears in this fixture. Use subgradients at the absolute-value corner; distinguish objective sparsity from a solver merely returning a small number.

08:00recommended time

Closing or reloading clears the scratchpad. Only score, weak rubric dimensions, attempt count, and retry date can be stored locally.

Reading depth

Compare the exact fitted coefficients produced by absolute and squared penalties under one explicitly defined quadratic objective.

Problem

Context. Fit using data loss and coefficient . Compare L1 penalty with half-scaled L2 penalty .

Task. Derive the minimizing coefficients for each penalized objective and identify which coefficients become exactly zero. Explain how changing the penalty convention or feature scaling changes the comparison.

Constraints. Coordinates are independent, feature units are comparable, and no intercept appears in this fixture. Use subgradients at the absolute-value corner; distinguish objective sparsity from a solver merely returning a small number.

Fix the objective

Use L1 penalty and L2 penalty . An unhalved L2 convention, , doubles its penalty derivative for the same numerical coefficient. Changing summed loss to mean loss also changes relative penalty strength unless rescaled. State intercept treatment and feature scaling in a real fit.

Solve the corner and the smooth condition

For one L1 coordinate, minimize .

  • If , stationarity gives , valid for .
  • If , it gives , valid for .
  • At zero, holds exactly when .

Together these give . For L2, gives .

ObjectiveFirst coordinateSecond coordinate
Unpenalized
L1, since
Half-scaled L2

Learning objective

An L1 corner can touch the loss at an exactly zero coefficient

A corner can put one coefficient exactly at zeroFor squared distance from (2,0.4), the unit L1 constraint selects (1,0). The unit L2 constraint selects a nonzero second coordinate.The nearest feasible point meets aboundarytarget (2, 0.4)Diamond contact: (1, 0)Circle contact: (0.9806, 0.1961)Only the corner lies exactly on thecoordinate axis.
Derivation
L1 contact at an axis corner A diamond-shaped equal-L1 boundary is centered at the origin of a w1 and w2 coefficient plane. A circular loss contour centered on the shared unconstrained minimum first touches the diamond at its right corner on the w1 axis. The marked constrained optimum therefore has positive w1 and w2 exactly zero. L1 · CORNER CAN ZERO A COEFFICIENT w1 w2 |w1| + |w2| ≤ t loss contour no penalty first contact w2 = 0
L2 contact away from both axes A circular equal-L2 boundary is centered at the origin of the same w1 and w2 coefficient plane. A loss contour centered on the same unconstrained minimum first touches the smooth boundary between the axes. The marked constrained optimum therefore keeps both w1 and w2 nonzero. L2 · SMOOTH CONTACT IS USUALLY DENSE w1 w2 w1² + w2² ≤ t loss contour no penalty first contact w1, w2 ≠ 0
expand a loss contour from the star until it touches the allowed region. A diamond corner can zero a coefficient; a smooth-circle contact can retain both. This schematic illustrates a tendency, not the numerical coordinates of our separate analytic fixture. Equivalent constrained budgets depend on the fitted optimum; equal numeric budgets across norms are not equivalent penalties. Sources: Tibshirani's lasso paper and The Elements of Statistical Learning.
Check: What feature of the L1 boundary makes a zero coefficient possible at first contact?
Read it this way: For squared distance from (2,0.4), the unit L1 constraint selects (1,0). The unit L2 constraint selects a nonzero second coordinate.
Which boundary has a corner on a coordinate axis?

Change the requirements

New task: reduce L1 strength to while keeping the fitting surface fixed. Move the threshold inward. Check: ; the removed coefficient returns. Use when: validation or a feature-count requirement favors less sparsity.

New task: combine L1 strength with L2 strength . Threshold, then shrink: , giving . Use when: sparse selection and correlated-feature stability both matter. Boundary: this reference has independent coordinates; correlated designs require solving the coupled objective.

Failure: for , step size one sends to , then alternates between and . The optimum is zero; fixed-step subgradient updates need not reach it. Numerical jitter is not an exact-sparsity method.

Reconstruct: multiply a feature by while preserving its prediction contribution. Is its coefficient penalty unchanged?

Answer

No. Its coefficient becomes one hundredth as large. The same contribution receives one hundredth the L1 penalty and one ten-thousandth the L2 penalty. Standardize features or justify scale-specific penalties.

Priors and solver choices

Independent Laplace and Gaussian priors yield L1 and L2 MAP penalties under matching likelihood units and scale. MAP is a point estimate, not the whole posterior. Intercept exclusions and rescaled features alter that interpretation.

Proximal gradient methods apply soft thresholding after the smooth-loss step; their threshold includes step size. ISTA, FISTA, coordinate descent, and specialized solvers handle nonsmoothness explicitly. The separable closed form does not extend unchanged to an arbitrary correlated design. See Parikh and Boyd’s Proximal Algorithms.

Keep optimizer effects separate

For frozen coordinate preconditioners, a coupled L2 gradient is preconditioned; AdamW’s shrinkage is separate. The decay trace computes that difference. Neither procedure is universally preferable for every statistical objective.

Optimizer noise, architecture, and early stopping can bias fitted solutions without an explicit penalty. Their generalization effects and relative importance depend on workload and training protocol.

Common follow-up

When should decay be disabled? Compare matched validation outcomes, parameter groups, schedules, and deployment constraints, including a zero-decay control. Model size alone does not prescribe a universal coefficient.


Related: regularization and Adam and AdamW.