Lasso Regression
What you'll learn
- Why Lasso (Least Absolute Shrinkage and Selection Operator) uniquely performs automatic feature selection.
- How the geometry of the diamond constraint produces exact zeros (), unlike the smooth circle of Ridge.
- Why the non-differentiable absolute value function prevents a closed-form matrix inverse and necessitates subgradients.
- The Karush-Kuhn-Tucker (KKT) optimality conditions governing sparse solutions.
- The closed-form Soft-Thresholding Operator .
- How the Coordinate Descent algorithm solves Lasso by cycling through one parameter at a time.
- How to determine the all-zero threshold and select the optimal hyperparameter via cross-validation.
Explained in detail
1. The Big Picture: What is Lasso Regression?
In machine learning and statistics, we often encounter datasets with dozens or hundreds of candidate features, many of which may be irrelevant, noisy, or redundant.
While Ordinary Least Squares (OLS) assigns a non-zero weight to every available feature, and Ridge Regression shrinks coefficients toward zero without ever discarding any, Lasso Regression (Least Absolute Shrinkage and Selection Operator) accomplishes two tasks simultaneously:
- Regularization: It prevents overfitting by shrinking coefficient magnitudes.
- Feature Selection: It drives uninformative or redundant coefficients to exactly zero, producing a sparse, interpretable model.
The Lasso objective function is:
In matrix notation:
where is the regularization tuning parameter.
2. The Penalty and Geometric Intuition
To understand why Lasso produces exact zeros while Ridge does not, we examine the problem from a constrained optimization perspective (Lagrangian duality):
where is an allowable coefficient budget inversely related to .

In 2D parameter space :
- The OLS Contours (Blue Ellipses): Centered at the unconstrained minimum . Each ellipse traces parameter combinations that share identical Residual Sum of Squares.
- The Constraint (Ridge Circle): The constraint is a smooth sphere/circle. The expanding ellipse touches the circle along its smooth curved edge, retaining non-zero values for both parameters.
- The Constraint (Lasso Diamond): The constraint is a rotated square (diamond) whose sharp corners (vertices) lie precisely on the coordinate axes:
Why Corners Cause Exact Zeros
Because the diamond constraint has sharp pointy corners aligned with the coordinate axes, the expanding elliptical RSS contours have a very high mathematical probability of first making contact with the boundary at a corner!
When contact occurs at the corner , parameter is strictly zero:
Feature is completely pruned from the model!
3. Optimization: Why Doesn't Lasso Have a Matrix Inverse?
Students often ask: Why can we invert a matrix to solve Ridge , but cannot do the same for Lasso?
The answer lies in calculus. The absolute value function has a sharp, non-differentiable corner (kink) at :
Because the derivative does not exist at zero, we cannot differentiate the objective using standard calculus to set up a linear system of equations.
Subgradients
For non-differentiable convex functions, we generalize the derivative using subgradients. A scalar is a subgradient of a convex function at point if the line with slope passing through lies everywhere on or below the graph of .
For the absolute value function , the subdifferential is:
At the sharp corner , any slope between and is a valid subgradient! This continuous interval is the exact mathematical mechanism that allows solutions to lock onto zero across a wide range of data configurations.
The subgradient optimality condition for Lasso is:
4. Karush-Kuhn-Tucker (KKT) Optimality Conditions
Let denote the -th column of , and let denote the final residual vector. The -th coordinate condition from the subgradient equation is:
Evaluating the three cases of the subdifferential yields the Coordinate-wise KKT Conditions:
The KKT Threshold Intuition: For a feature to have a non-zero coefficient, its sample correlation with the residual () must hit the upper or lower boundary . If its correlation falls within the interior deadband , the feature is not informative enough to justify its penalty cost, and its coefficient remains locked at exact zero!
5. The Soft-Thresholding Operator
When predictors are orthogonal (), the multivariate Lasso problem uncouples into independent scalar minimization problems. Each coordinate solution is given by the Soft-Thresholding Operator:
Equivalently written piecewise:

Notice how soft-thresholding operates:
- Deadband : Any input whose magnitude is less than or equal to is snapped strictly to zero!
- Outside the Deadband: Inputs exceeding in magnitude are preserved, but shrunk toward zero by a constant offset of .
6. The Coordinate Descent Algorithm
Because we cannot solve for all coefficients simultaneously in one matrix inversion, how do modern libraries (like scikit-learn and glmnet) solve Lasso? They use Coordinate Descent.

The Core Idea
Instead of updating all parameters at once, Coordinate Descent minimizes the objective with respect to one coordinate at a time, while keeping all other coordinates fixed at their current values.
Let be the partial residual calculated by removing the effect of feature :
The single-coordinate subproblem reduces to:
This univariate problem has a closed-form solution given directly by soft-thresholding!
The Coordinate Update Formula
When features are standardized so that , the update simplifies to:
Numerical Example
Suppose for feature , , , and penalty (so threshold ):
If instead the correlation was weak, say :
The coefficient is instantly pruned!
The algorithm repeatedly cycles through coordinates until the maximum coefficient change falls below a convergence tolerance (e.g., ).
7. Practical Modeling: Scaling and Choosing
Mandatory Feature Standardization
Because the penalty sums the raw absolute values , features measured in large units (e.g., house price in millions vs. number of bathrooms) will have arbitrarily small coefficients and escape penalization.
Always standardize features using training set statistics:
The All-Zero Threshold ()
At what penalty value do all coefficients become zero? Using the KKT conditions at , every coordinate condition must hold. Thus:
Any yields the trivial null model . Effective grids for hyperparameter search typically span logarithmically from down to .
Cross-Validation Workflow
We select the optimal using -Fold Cross-Validation:


- Regularization Path: As is decreased from , features enter the active set one by one.
- vs : We can select the with the absolute lowest cross-validation error (), or use the 1-Standard-Error rule ()—the simplest (sparsest) model whose error is within one standard error of the minimum.
8. Strengths & Limitations of Lasso
Strengths
- Interpretability: Prunes irrelevant features, leaving a compact, readable formula.
- High-Dimensional Regression (): When there are more features than observations, OLS is undefined. Lasso can select at most predictors and provides stable estimates.
Limitations & Motivation for Elastic Net
- Correlated Predictor Selection: When two features are strongly collinear (), Lasso tends to arbitrarily select one and zero out the other.
- Constraint on Active Set: If , Lasso can never select more than variables.
- Over-Shrinkage of Large Slopes: Because the penalty subtracts a constant offset from all surviving coefficients, true large signals may suffer excess bias.
These limitations motivate Elastic Net, which combines both (Lasso) and (Ridge) penalties: .
Figure 3.5: Lasso Diamond Geometry & Exact Sparsity
Interactive Lasso Regularization. The sharp corners of the L₁ diamond constraint ||β||₁ ≤ s lie directly on coordinate axes. When the expanding RSS contour touches a corner, the corresponding parameter drops exactly to zero (automatic feature selection).
What to try
- Move the Slider:
- In Diamond Geometry View: Watch the amber diamond shrink as increases. Notice the moment contact hits the horizontal axis corner ( drops to exact while remains active).
- Toggle "+ Compare Ridge Circle": See how the green circular boundary touches the ellipse along a curve, keeping both parameters non-zero, while Lasso snaps to the corner.
- Switch to "Soft Thresholding":
- Examine the red shaded deadband . Notice how any input within this window is clamped to zero.
- Switch to "Regularization Paths":
- Watch intersect the horizontal axis at and remain flat at zero.
Key ideas at a glance
Summary Reference Table
Check your understanding
🧩
Ready to test yourself?
15 questions · explanations shown after
Teach & Solidify
Teach This: Lasso Regression (L1 Regularization)
Core Intuition
Lasso minimizes RSS + λ∑|βⱼ|. Its sharp diamond constraint drives uninformative coefficients to exact zero, performing simultaneous regularization and automatic feature selection via Coordinate Descent.
Key Concepts to Explain
- 1Lasso uses an L₁ penalty: ∑|βⱼ|.
- 2Sharp diamond corners on the axes make tangency occur at exact zero (sparsity).
- 3The kink at zero requires subgradient calculus: ∂|0| = [-1, 1].
- 4KKT conditions require |2xⱼᵀr| ≤ λ for a coefficient to remain zero.
- 5Coordinate Descent optimizes one feature at a time using the closed-form Soft-Thresholding Operator.
- 6Features must be standardized, and λ is tuned via K-fold cross-validation.
⚠️ What Most Students Get Confused About
Believing Lasso has a closed-form matrix formula like Ridge. Because the absolute value is non-differentiable at zero, Lasso cannot be solved with a simple matrix inverse; it must be solved iteratively via Coordinate Descent.
Explain Lasso Regression in your own words
Imagine you are explaining this idea to a friend or classmate with no math background. Writing it out forces your brain to bridge gaps in your intuition.
Resources & GitHub
Resources & Study Materials
Deepen your understanding with author-prepared study notes, derivation proofs, and curated educational lectures.
Author's comprehensive LaTeX notes covering L1 geometry, subgradient proofs, KKT conditions, coordinate descent derivations, and cross-validation.
Full editable LaTeX source code with tcolorbox styling, algorithm pseudocode, and mathematical environments.
Josh Starmer visually explains how Lasso shrinks coefficients to zero and performs automatic feature selection.
Mastered this concept?
Tick this box when you feel confident explaining it.
Topic Resources
Was this clear?