Lasso
The lasso (least absolute shrinkage and selection operator) fits a linear model by least squares. Its penalty is the sum of the absolute values of the coefficients. With standardized predictors and a centered response , it solves
where sets the strength of the penalty and the intercept is not penalized. The objective is convex, but it has no closed form because has a corner at zero. With the -th column of , a vector is a solution exactly when every satisfies
Every coefficient is zero once . The soft-thresholding function moves toward zero by and stops at zero. When , the lasso is , while ridge gives . Four facts describe its behavior:
- Sparsity: many coefficients are exactly zero, so the lasso selects variables.
- Coordinate descent: cycling through with converges to a solution. Here is the partial residual.
- At most predictors: when , the lasso keeps at most nonzero coefficients, or with a fitted intercept.
- Laplace prior: with Gaussian noise of variance and independent priors , the posterior mode is the lasso with .
Cross-validation chooses . The lasso fits when few predictors should matter or the model must name them. Ridge is preferred when many correlated predictors each carry signal. Elastic net is preferred when correlated groups should enter together.
Where the Factor of Two Goes
This note follows STAT 153 and ISLR and puts no before the squared error, so the threshold is . ESL and many papers minimize , where the threshold is . glmnet and scikit-learn minimize , so their equals this note’s .
Intuition
Ridge shrinks every coefficient but never to exactly zero. The lasso uses an absolute value in place of the squared penalty, and with it the lasso selects variables. The squared penalty has slope , which vanishes near zero, so a tiny coefficient costs almost nothing. The absolute penalty has slope at every nonzero value. Take a predictor whose fit gradient stays below . A small nonzero coefficient then adds more penalty than it removes squared error, so the coefficient stays at zero. Tibshirani (1996) chose the name because the method both shrinks coefficients and selects predictors.
The constrained form has a geometric reading. The lasso minimizes the squared error over the region . In two dimensions this region is a diamond with corners on the axes. The elliptical contours of the squared error often first touch the diamond at a corner, where one coefficient is zero. Ridge uses a disk, which has no corners, so the contact point almost never lies on an axis. In higher dimensions the ball has corners and edges on many coordinate subspaces, and sparse solutions become more common.
The animation uses the same five predictors as the one in 3.2.1. Ridge Regression. The coefficients hit exactly zero one at a time. Each dot on the right sits at on , so a coefficient is zero once .
\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{grn}{HTML}{2F9E44}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\draw[->] (0,-2.35) -- (7.75,-2.35) node[right] {$\log_{10}\lambda$};
\draw[->] (0,-2.35) -- (0,3.15) node[above] {$\beta_j$};
\draw[dashed] (0,0) -- (7.40,0);
\draw (0.70,-2.35) -- (0.70,-2.43) node[below] {\footnotesize $-1$};
\draw (2.46,-2.35) -- (2.46,-2.43) node[below] {\footnotesize $-0.5$};
\draw (4.22,-2.35) -- (4.22,-2.43) node[below] {\footnotesize $0$};
\draw (5.99,-2.35) -- (5.99,-2.43) node[below] {\footnotesize $0.5$};
\draw (0,-1.20) -- (-0.08,-1.20) node[left] {\footnotesize $-1$};
\draw (0,1.20) -- (-0.08,1.20) node[left] {\footnotesize $1$};
\draw (0,2.40) -- (-0.08,2.40) node[left] {\footnotesize $2$};
\node[anchor=west] at (-0.9,-3.10) {\footnotesize hits $0$:};
\draw[hot, very thick] (0.00,2.60) -- (0.15,2.60) -- (0.30,2.59) -- (0.45,2.59) -- (0.60,2.58) -- (0.76,2.58) -- (0.91,2.57) -- (1.06,2.56) -- (1.21,2.56) -- (1.36,2.55) -- (1.51,2.54) -- (1.66,2.53) -- (1.81,2.52) -- (1.96,2.50) -- (2.11,2.49) -- (2.27,2.47) -- (2.42,2.46) -- (2.57,2.44) -- (2.72,2.42) -- (2.87,2.39) -- (3.02,2.37) -- (3.10,2.35) -- (3.17,2.34) -- (3.32,2.31) -- (3.47,2.28) -- (3.62,2.24) -- (3.78,2.20) -- (3.93,2.15) -- (4.08,2.10) -- (4.23,2.04) -- (4.28,2.02) -- (4.38,1.99) -- (4.53,1.94) -- (4.68,1.88) -- (4.72,1.86) -- (4.83,1.83) -- (4.98,1.78) -- (5.13,1.72) -- (5.29,1.66) -- (5.44,1.59) -- (5.51,1.56) -- (5.59,1.48) -- (5.74,1.33) -- (5.89,1.17) -- (6.04,0.98) -- (6.19,0.78) -- (6.34,0.55) -- (6.49,0.30) -- (6.64,0.03) -- (6.66,0.00) -- (6.80,0.00) -- (6.95,0.00) -- (7.10,0.00) -- (7.25,0.00) -- (7.40,0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,2.63) {\footnotesize $\beta_1$};
\draw[hot, dashed, very thick] (0.00,1.04) -- (0.15,1.04) -- (0.30,1.03) -- (0.45,1.03) -- (0.60,1.02) -- (0.76,1.02) -- (0.91,1.01) -- (1.06,1.00) -- (1.21,1.00) -- (1.36,0.99) -- (1.51,0.98) -- (1.66,0.97) -- (1.81,0.96) -- (1.96,0.94) -- (2.11,0.93) -- (2.27,0.91) -- (2.42,0.90) -- (2.57,0.88) -- (2.72,0.86) -- (2.87,0.83) -- (3.02,0.81) -- (3.10,0.79) -- (3.17,0.78) -- (3.32,0.75) -- (3.47,0.72) -- (3.62,0.68) -- (3.78,0.64) -- (3.93,0.59) -- (4.08,0.54) -- (4.23,0.48) -- (4.28,0.46) -- (4.38,0.43) -- (4.53,0.38) -- (4.68,0.32) -- (4.72,0.30) -- (4.83,0.27) -- (4.98,0.22) -- (5.13,0.16) -- (5.29,0.10) -- (5.44,0.03) -- (5.51,0.00) -- (5.59,0.00) -- (5.74,0.00) -- (5.89,0.00) -- (6.04,0.00) -- (6.19,0.00) -- (6.34,0.00) -- (6.49,0.00) -- (6.64,0.00) -- (6.66,0.00) -- (6.80,0.00) -- (6.95,0.00) -- (7.10,0.00) -- (7.25,0.00) -- (7.40,0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,1.07) {\footnotesize $\beta_2$};
\draw[cold, very thick] (0.00,-1.93) -- (0.15,-1.92) -- (0.30,-1.91) -- (0.45,-1.90) -- (0.60,-1.88) -- (0.76,-1.87) -- (0.91,-1.85) -- (1.06,-1.83) -- (1.21,-1.81) -- (1.36,-1.78) -- (1.51,-1.76) -- (1.66,-1.73) -- (1.81,-1.69) -- (1.96,-1.66) -- (2.11,-1.62) -- (2.27,-1.57) -- (2.42,-1.53) -- (2.57,-1.47) -- (2.72,-1.41) -- (2.87,-1.35) -- (3.02,-1.28) -- (3.10,-1.24) -- (3.17,-1.20) -- (3.32,-1.11) -- (3.47,-1.01) -- (3.62,-0.91) -- (3.78,-0.79) -- (3.93,-0.66) -- (4.08,-0.52) -- (4.23,-0.36) -- (4.28,-0.31) -- (4.38,-0.24) -- (4.53,-0.14) -- (4.68,-0.03) -- (4.72,-0.00) -- (4.83,0.00) -- (4.98,0.00) -- (5.13,0.00) -- (5.29,0.00) -- (5.44,0.00) -- (5.51,0.00) -- (5.59,0.00) -- (5.74,0.00) -- (5.89,0.00) -- (6.04,0.00) -- (6.19,0.00) -- (6.34,0.00) -- (6.49,0.00) -- (6.64,0.00) -- (6.66,0.00) -- (6.80,0.00) -- (6.95,0.00) -- (7.10,0.00) -- (7.25,0.00) -- (7.40,0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,-1.90) {\footnotesize $\beta_3$};
\draw[cold, dashed, very thick] (0.00,1.46) -- (0.15,1.45) -- (0.30,1.44) -- (0.45,1.42) -- (0.60,1.41) -- (0.76,1.40) -- (0.91,1.38) -- (1.06,1.36) -- (1.21,1.34) -- (1.36,1.32) -- (1.51,1.29) -- (1.66,1.26) -- (1.81,1.23) -- (1.96,1.20) -- (2.11,1.16) -- (2.27,1.12) -- (2.42,1.07) -- (2.57,1.02) -- (2.72,0.97) -- (2.87,0.90) -- (3.02,0.84) -- (3.10,0.80) -- (3.17,0.77) -- (3.32,0.69) -- (3.47,0.61) -- (3.62,0.52) -- (3.78,0.42) -- (3.93,0.30) -- (4.08,0.18) -- (4.23,0.05) -- (4.28,0.00) -- (4.38,0.00) -- (4.53,0.00) -- (4.68,0.00) -- (4.72,0.00) -- (4.83,0.00) -- (4.98,0.00) -- (5.13,0.00) -- (5.29,0.00) -- (5.44,0.00) -- (5.51,0.00) -- (5.59,0.00) -- (5.74,0.00) -- (5.89,0.00) -- (6.04,0.00) -- (6.19,0.00) -- (6.34,0.00) -- (6.49,0.00) -- (6.64,0.00) -- (6.66,0.00) -- (6.80,0.00) -- (6.95,0.00) -- (7.10,0.00) -- (7.25,0.00) -- (7.40,0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,1.49) {\footnotesize $\beta_4$};
\draw[black, very thick] (0.00,-0.31) -- (0.15,-0.31) -- (0.30,-0.30) -- (0.45,-0.30) -- (0.60,-0.29) -- (0.76,-0.28) -- (0.91,-0.27) -- (1.06,-0.27) -- (1.21,-0.26) -- (1.36,-0.24) -- (1.51,-0.23) -- (1.66,-0.22) -- (1.81,-0.20) -- (1.96,-0.19) -- (2.11,-0.17) -- (2.27,-0.15) -- (2.42,-0.13) -- (2.57,-0.11) -- (2.72,-0.08) -- (2.87,-0.05) -- (3.02,-0.02) -- (3.10,-0.00) -- (3.17,0.00) -- (3.32,0.00) -- (3.47,0.00) -- (3.62,0.00) -- (3.78,0.00) -- (3.93,0.00) -- (4.08,0.00) -- (4.23,0.00) -- (4.28,0.00) -- (4.38,0.00) -- (4.53,0.00) -- (4.68,0.00) -- (4.72,0.00) -- (4.83,0.00) -- (4.98,0.00) -- (5.13,0.00) -- (5.29,0.00) -- (5.44,0.00) -- (5.51,0.00) -- (5.59,0.00) -- (5.74,0.00) -- (5.89,0.00) -- (6.04,0.00) -- (6.19,0.00) -- (6.34,0.00) -- (6.49,0.00) -- (6.64,0.00) -- (6.66,0.00) -- (6.80,0.00) -- (6.95,0.00) -- (7.10,0.00) -- (7.25,0.00) -- (7.40,0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,-0.28) {\footnotesize $\beta_5$};
\draw[->] (9.65,0.05) -- (14.55,0.05) node[right] {$z$};
\draw[->] (12.0,-2.21) -- (12.0,2.50) node[right] {$S_{\lambda/2}(z)$};
\draw[dashed] (9.75,-2.21) -- (14.25,2.30) ;
\node at (12.00,3.40) {soft threshold $S_{\lambda/2}(z) = \mathrm{sign}(z)\max(|z| - \lambda/2, 0)$};
\node at (12.00,2.90) {\footnotesize dot $j$ at $(z_j, \beta_j)$, \ $z_j = \mathbf x_j^T(\mathbf y - \sum_{k \ne j} \mathbf x_k\beta_k)$};
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.36s = "true", 20.8s = "true", repeats}}}]
\draw[very thick] (3.10,0) circle (4.5pt);
\draw (3.10,-2.35) -- (3.10,-2.23);
\node at (3.10,-3.10) {\footnotesize $\beta_5$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.28s = "true", 20.8s = "true", repeats}}}]
\draw[very thick] (4.28,0) circle (4.5pt);
\draw (4.28,-2.35) -- (4.28,-2.23);
\node at (4.28,-3.10) {\footnotesize $\beta_4$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.96s = "true", 20.8s = "true", repeats}}}]
\draw[very thick] (4.72,0) circle (4.5pt);
\draw (4.72,-2.35) -- (4.72,-2.23);
\node at (4.72,-3.10) {\footnotesize $\beta_3$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.88s = "true", 20.8s = "true", repeats}}}]
\draw[very thick] (5.51,0) circle (4.5pt);
\draw (5.51,-2.35) -- (5.51,-2.23);
\node at (5.51,-3.10) {\footnotesize $\beta_2$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 14.8s = "true", 20.8s = "true", repeats}}}]
\draw[very thick] (6.66,0) circle (4.5pt);
\draw (6.66,-2.35) -- (6.66,-2.23);
\node at (6.66,-3.10) {\footnotesize $\beta_1$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.4s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (0.00,-2.35) -- (0.00,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.06$};
\filldraw[draw=black, fill=hot] (0.00,2.60) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (0.00,1.04) circle (2.4pt);
\filldraw[draw=black, fill=cold] (0.00,-1.93) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (0.00,1.46) circle (2.4pt);
\filldraw[draw=black, fill=black] (0.00,-0.31) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-2.18) -- (11.97,0.05) -- (12.03,0.05) -- (14.25,2.28);
\filldraw[draw=black, fill=hot] (13.80,1.83) circle (2.4pt);
\filldraw[draw=black, fill=cold] (10.65,-1.27) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (13.02,1.05) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.76) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.76,-0.16) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {Small $\lambda$: the lasso is close to OLS. All five coefficients are nonzero.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 2.64s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (0.32,-2.35) -- (0.32,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.08$};
\filldraw[draw=black, fill=hot] (0.32,2.59) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (0.32,1.03) circle (2.4pt);
\filldraw[draw=black, fill=cold] (0.32,-1.91) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (0.32,1.44) circle (2.4pt);
\filldraw[draw=black, fill=black] (0.32,-0.30) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-2.17) -- (11.97,0.05) -- (12.03,0.05) -- (14.25,2.27);
\filldraw[draw=black, fill=hot] (13.80,1.82) circle (2.4pt);
\filldraw[draw=black, fill=cold] (10.66,-1.25) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (13.01,1.03) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.76) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.76,-0.16) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.64s = "true", 2.88s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (1.09,-2.35) -- (1.09,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.13$};
\filldraw[draw=black, fill=hot] (1.09,2.56) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (1.09,1.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (1.09,-1.82) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (1.09,1.35) circle (2.4pt);
\filldraw[draw=black, fill=black] (1.09,-0.26) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-2.15) -- (11.95,0.05) -- (12.05,0.05) -- (14.25,2.25);
\filldraw[draw=black, fill=hot] (13.80,1.80) circle (2.4pt);
\filldraw[draw=black, fill=cold] (10.70,-1.20) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.98,0.98) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.74) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.77,-0.13) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.88s = "true", 3.12s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (2.01,-2.35) -- (2.01,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.24$};
\filldraw[draw=black, fill=hot] (2.01,2.50) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (2.01,0.94) circle (2.4pt);
\filldraw[draw=black, fill=cold] (2.01,-1.65) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (2.01,1.19) circle (2.4pt);
\filldraw[draw=black, fill=black] (2.01,-0.18) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-2.11) -- (11.90,0.05) -- (12.10,0.05) -- (14.25,2.21);
\filldraw[draw=black, fill=hot] (13.80,1.76) circle (2.4pt);
\filldraw[draw=black, fill=cold] (10.78,-1.07) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.91,0.86) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.69) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.78,-0.08) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.12s = "true", 3.36s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (2.78,-2.35) -- (2.78,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.39$};
\filldraw[draw=black, fill=hot] (2.78,2.41) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (2.78,0.85) circle (2.4pt);
\filldraw[draw=black, fill=cold] (2.78,-1.39) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (2.78,0.94) circle (2.4pt);
\filldraw[draw=black, fill=black] (2.78,-0.07) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-2.05) -- (11.84,0.05) -- (12.16,0.05) -- (14.25,2.15);
\filldraw[draw=black, fill=hot] (13.80,1.70) circle (2.4pt);
\filldraw[draw=black, fill=cold] (10.89,-0.90) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.80,0.69) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.63) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.79,0.00) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.36s = "true", 5.56s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (3.10,-2.35) -- (3.10,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.48$};
\filldraw[draw=black, fill=hot] (3.10,2.35) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (3.10,0.79) circle (2.4pt);
\filldraw[draw=black, fill=cold] (3.10,-1.24) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (3.10,0.80) circle (2.4pt);
\filldraw[draw=black, fill=black] (3.10,-0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-2.01) -- (11.80,0.05) -- (12.20,0.05) -- (14.25,2.11);
\filldraw[draw=black, fill=hot] (13.81,1.66) circle (2.4pt);
\filldraw[draw=black, fill=cold] (10.96,-0.79) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.74,0.59) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.59) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.80,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda = 0.48$: $\beta_5$ hits exactly $0$. Its $z_5$ enters the flat part $|z| \le \lambda/2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.56s = "true", 5.8s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (3.29,-2.35) -- (3.29,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.54$};
\filldraw[draw=black, fill=hot] (3.29,2.32) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (3.29,0.76) circle (2.4pt);
\filldraw[draw=black, fill=cold] (3.29,-1.13) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (3.29,0.71) circle (2.4pt);
\filldraw[draw=black, fill=black] (3.29,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.98) -- (11.78,0.05) -- (12.22,0.05) -- (14.25,2.08);
\filldraw[draw=black, fill=hot] (13.81,1.63) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.00,-0.72) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.57) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.71,0.53) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.81,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.8s = "true", 6.04s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (3.69,-2.35) -- (3.69,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.70$};
\filldraw[draw=black, fill=hot] (3.69,2.22) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (3.69,0.66) circle (2.4pt);
\filldraw[draw=black, fill=cold] (3.69,-0.86) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (3.69,0.47) circle (2.4pt);
\filldraw[draw=black, fill=black] (3.69,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.92) -- (11.71,0.05) -- (12.29,0.05) -- (14.25,2.02);
\filldraw[draw=black, fill=hot] (13.81,1.57) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.12,-0.54) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.50) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.61,0.37) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.82,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.04s = "true", 6.28s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (4.09,-2.35) -- (4.09,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.92$};
\filldraw[draw=black, fill=hot] (4.09,2.09) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.09,0.53) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.09,-0.50) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.09,0.17) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.09,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.83) -- (11.62,0.05) -- (12.38,0.05) -- (14.25,1.93);
\draw (11.62,-0.03) -- (11.62,0.13);
\node[above] at (11.62,0.13) {\footnotesize $-\lambda/2$};
\draw (12.38,-0.03) -- (12.38,0.13);
\node[below] at (12.38,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.81,1.48) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.41) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.28,-0.29) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.49,0.16) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.84,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.28s = "true", 8.48s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (4.28,-2.35) -- (4.28,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.03$};
\filldraw[draw=black, fill=hot] (4.28,2.02) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.28,0.46) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.28,-0.31) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.28,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.28,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.78) -- (11.58,0.05) -- (12.42,0.05) -- (14.25,1.88);
\draw (11.58,-0.03) -- (11.58,0.13);
\node[above] at (11.58,0.13) {\footnotesize $-\lambda/2$};
\draw (12.42,-0.03) -- (12.42,0.13);
\node[below] at (12.42,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.81,1.43) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.74,0.37) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.37,-0.16) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.42,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.85,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda = 1.03$: $\beta_4$ hits exactly $0$. Its $z_4$ enters the flat part $|z| \le \lambda/2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.48s = "true", 8.72s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (4.39,-2.35) -- (4.39,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.11$};
\filldraw[draw=black, fill=hot] (4.39,1.99) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.39,0.43) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.39,-0.23) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.39,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.39,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.75) -- (11.54,0.05) -- (12.46,0.05) -- (14.25,1.85);
\draw (11.54,-0.03) -- (11.54,0.13);
\node[above] at (11.54,0.13) {\footnotesize $-\lambda/2$};
\draw (12.46,-0.03) -- (12.46,0.13);
\node[below] at (12.46,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.81,1.41) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.75,0.34) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.38,-0.11) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.40,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.84,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.72s = "true", 8.96s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (4.60,-2.35) -- (4.60,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.28$};
\filldraw[draw=black, fill=hot] (4.60,1.91) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.60,0.35) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.60,-0.09) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.60,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.60,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.68) -- (11.47,0.05) -- (12.53,0.05) -- (14.25,1.78);
\draw (11.47,-0.03) -- (11.47,0.13);
\node[above] at (11.47,0.13) {\footnotesize $-\lambda/2$};
\draw (12.53,-0.03) -- (12.53,0.13);
\node[below] at (12.53,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.83,1.35) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.76,0.29) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.41,-0.01) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.35,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.96s = "true", 11.16s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (4.72,-2.35) -- (4.72,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.38$};
\filldraw[draw=black, fill=hot] (4.72,1.86) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.72,0.30) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.72,-0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.72,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.72,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.64) -- (11.43,0.05) -- (12.57,0.05) -- (14.25,1.74);
\draw (11.43,-0.03) -- (11.43,0.13);
\node[above] at (11.43,0.13) {\footnotesize $-\lambda/2$};
\draw (12.57,-0.03) -- (12.57,0.13);
\node[below] at (12.57,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.84,1.32) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.77,0.26) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.43,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda = 1.38$: $\beta_3$ hits exactly $0$. Its $z_3$ enters the flat part $|z| \le \lambda/2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.16s = "true", 11.4s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (4.84,-2.35) -- (4.84,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.50$};
\filldraw[draw=black, fill=hot] (4.84,1.82) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.84,0.26) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.84,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.84,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.84,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.59) -- (11.39,0.05) -- (12.61,0.05) -- (14.25,1.69);
\draw (11.39,-0.03) -- (11.39,0.13);
\node[above] at (11.39,0.13) {\footnotesize $-\lambda/2$};
\draw (12.61,-0.03) -- (12.61,0.13);
\node[below] at (12.61,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.86,1.30) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.79,0.23) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.45,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.4s = "true", 11.64s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (5.11,-2.35) -- (5.11,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.79$};
\filldraw[draw=black, fill=hot] (5.11,1.73) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (5.11,0.17) circle (2.4pt);
\filldraw[draw=black, fill=cold] (5.11,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (5.11,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (5.11,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.47) -- (11.27,0.05) -- (12.73,0.05) -- (14.25,1.57);
\draw (11.27,-0.03) -- (11.27,0.13);
\node[above] at (11.27,0.13) {\footnotesize $-\lambda/2$};
\draw (12.73,-0.03) -- (12.73,0.13);
\node[below] at (12.73,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.91,1.23) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.85,0.17) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.49,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.64s = "true", 11.88s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (5.38,-2.35) -- (5.38,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 2.13$};
\filldraw[draw=black, fill=hot] (5.38,1.62) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (5.38,0.06) circle (2.4pt);
\filldraw[draw=black, fill=cold] (5.38,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (5.38,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (5.38,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.33) -- (11.13,0.05) -- (12.87,0.05) -- (14.25,1.43);
\draw (11.13,-0.03) -- (11.13,0.13);
\node[above] at (11.13,0.13) {\footnotesize $-\lambda/2$};
\draw (12.87,-0.03) -- (12.87,0.13);
\node[below] at (12.87,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (13.98,1.16) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.91,0.09) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.53,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.88s = "true", 14.08s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (5.51,-2.35) -- (5.51,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 2.31$};
\filldraw[draw=black, fill=hot] (5.51,1.56) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (5.51,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (5.51,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (5.51,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (5.51,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.26) -- (11.05,0.05) -- (12.95,0.05) -- (14.25,1.36);
\draw (11.05,-0.03) -- (11.05,0.13);
\node[above] at (11.05,0.13) {\footnotesize $-\lambda/2$};
\draw (12.95,-0.03) -- (12.95,0.13);
\node[below] at (12.95,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (14.01,1.12) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (12.95,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.56,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda = 2.31$: $\beta_2$ hits exactly $0$. Its $z_2$ enters the flat part $|z| \le \lambda/2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 14.08s = "true", 14.32s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (5.69,-2.35) -- (5.69,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 2.60$};
\filldraw[draw=black, fill=hot] (5.69,1.39) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (5.69,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (5.69,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (5.69,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (5.69,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-1.14) -- (10.93,0.05) -- (13.07,0.05) -- (14.25,1.24);
\draw (10.93,-0.03) -- (10.93,0.13);
\node[above] at (10.93,0.13) {\footnotesize $-\lambda/2$};
\draw (13.07,-0.03) -- (13.07,0.13);
\node[below] at (13.07,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (14.01,1.00) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.05,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.59,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 14.32s = "true", 14.56s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (6.08,-2.35) -- (6.08,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 3.37$};
\filldraw[draw=black, fill=hot] (6.08,0.93) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (6.08,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (6.08,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (6.08,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (6.08,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-0.82) -- (10.62,0.05) -- (13.38,0.05) -- (14.25,0.92);
\draw (10.62,-0.03) -- (10.62,0.13);
\node[above] at (10.62,0.13) {\footnotesize $-\lambda/2$};
\draw (13.38,-0.03) -- (13.38,0.13);
\node[below] at (13.38,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (14.01,0.68) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.32,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.69,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 14.56s = "true", 14.8s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (6.48,-2.35) -- (6.48,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 4.36$};
\filldraw[draw=black, fill=hot] (6.48,0.33) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (6.48,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (6.48,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (6.48,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (6.48,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-0.42) -- (10.21,0.05) -- (13.79,0.05) -- (14.25,0.52);
\draw (10.21,-0.03) -- (10.21,0.13);
\node[above] at (10.21,0.13) {\footnotesize $-\lambda/2$};
\draw (13.79,-0.03) -- (13.79,0.13);
\node[below] at (13.79,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (14.01,0.27) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.66,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.81,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The nonzero coefficients keep shrinking.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 14.8s = "true", 17s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (6.66,-2.35) -- (6.66,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 4.91$};
\filldraw[draw=black, fill=hot] (6.66,0.00) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (6.66,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (6.66,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (6.66,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (6.66,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,-0.19) -- (9.99,0.05) -- (14.01,0.05) -- (14.25,0.29);
\draw (9.99,-0.03) -- (9.99,0.13);
\node[above] at (9.99,0.13) {\footnotesize $-\lambda/2$};
\draw (14.01,-0.03) -- (14.01,0.13);
\node[below] at (14.01,-0.03) {\footnotesize $\lambda/2$};
\filldraw[draw=black, fill=hot] (14.01,0.05) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.85,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.88,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {$\lambda = 2\max_j |\mathbf x_j^T\mathbf y| = 4.91$: $\beta_1$ hits $0$. All $z_j$ lie in the flat part.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 17s = "true", 17.3s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (7.03,-2.35) -- (7.03,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 6.25$};
\filldraw[draw=black, fill=hot] (7.03,0.00) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (7.03,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (7.03,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (7.03,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (7.03,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,0.05) -- (9.75,0.05) -- (14.25,0.05) -- (14.25,0.05);
\filldraw[draw=black, fill=hot] (14.01,0.05) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.85,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.88,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {Above $\lambda_{\max}$ the model is empty.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 17.3s = "true", 17.6s = "false", 20.8s = "false", repeats}}}]
\draw[thick] (7.40,-2.35) -- (7.40,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 7.96$};
\filldraw[draw=black, fill=hot] (7.40,0.00) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (7.40,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (7.40,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (7.40,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (7.40,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,0.05) -- (9.75,0.05) -- (14.25,0.05) -- (14.25,0.05);
\filldraw[draw=black, fill=hot] (14.01,0.05) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.85,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.88,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {Above $\lambda_{\max}$ the model is empty.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 17.6s = "true", 20.8s = "true", repeats}}}]
\draw[thick] (7.40,-2.35) -- (7.40,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 7.96$};
\filldraw[draw=black, fill=hot] (7.40,0.00) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (7.40,0.00) circle (2.4pt);
\filldraw[draw=black, fill=cold] (7.40,0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (7.40,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (7.40,0.00) circle (2.4pt);
\draw[grn, ultra thick] (9.75,0.05) -- (9.75,0.05) -- (14.25,0.05) -- (14.25,0.05);
\filldraw[draw=black, fill=hot] (14.01,0.05) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (13.85,0.05) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (12.32,0.05) circle (2.4pt);
\filldraw[draw=black, fill=black] (11.83,0.05) circle (2.4pt);
\filldraw[draw=black, fill=cold] (11.88,0.05) circle (2.4pt);
\node[anchor=west] at (-0.9,-3.75) {The coefficients hit exactly $0$ one at a time. The lasso selects predictors.};
\end{scope}
\node at (12.00,-2.56) {\footnotesize green: $S_{\lambda/2}(z)$, \ dashed: the identity $z$};
\node[anchor=west] at (-0.9,-4.3) {\footnotesize lasso: minimize $\|\mathbf y - \mathbf X\beta\|^2 + \lambda\|\beta\|_1$ by coordinate descent, \ $\beta_j \leftarrow S_{\lambda/2}(z_j)$, \ same data as the ridge figure};
\end{tikzpicture}
\end{document}Properties
(Constant Shift on Large Effects) The lasso moves every surviving coefficient toward zero by the same amount, however large it is.
In an orthonormal design, soft-thresholding subtracts from each coefficient that survives. A large true effect therefore keeps a bias of , and that bias does not fade as the effect grows. Ridge shrinks by a fixed fraction, so its bias grows with the effect. Best-subset selection is hard thresholding, which keeps large coefficients unchanged and zeroes the rest (ESL Table 3.4). A single controls both selection and shrinkage. Removing noise predictors needs a large , which over-shrinks the true effects. Cross-validation therefore tends to choose a smaller and admit some noise predictors. A common fix refits OLS on the selected predictors. The relaxed lasso (Meinshausen, 2007) blends that refit with the lasso fit.
(At Most Predictors) When , some lasso solution uses at most predictors, and in general position that solution is the only one.
Let be the set of nonzero coefficients and their signs. The optimality conditions give . If the columns are linearly dependent, take with . Moving along leaves the fit unchanged. It also leaves unchanged until a sign flips, since . Moving until one coefficient hits zero gives another solution with a smaller active set. Repeating this leaves linearly independent active columns, and at most of them. Centering the columns lowers the rank to at most . For continuous predictors, the solution is unique with probability one (Tibshirani, 2013). A study with patients can therefore name at most genes.
(Unstable Selection Under Correlation) Among strongly correlated predictors, the lasso tends to keep one, and small changes in the data switch which one.
With two identical columns, every same-sign split of their total coefficient gives the same objective. The solution is then not unique. With nearly identical columns the solution is unique, but a tiny change in the data can swap the chosen predictor. The lasso picks the true predictors consistently only under the irrepresentable condition (Zhao and Yu, 2006). That condition fails when an irrelevant predictor is strongly correlated with the relevant ones. Two remedies are common. Elastic net adds a ridge term that makes correlated predictors share the weight. Stability selection (Meinshausen and Bühlmann, 2010) refits the lasso on many random half-samples. It keeps the predictors chosen in a large fraction of the fits.
(Solving Along a Path) Solvers compute the lasso for a whole decreasing grid of values, each starting from the previous solution.
glmnet (Friedman, Hastie and Tibshirani, 2010) starts at , where the solution is zero. It then lowers along a log-spaced grid to a small fraction of . Each fit starts from the previous solution, so coordinate descent needs only a few sweeps of cost each. The solver updates only the active coefficients and then checks the optimality conditions for the rest. Coordinate descent converges here because the nonsmooth part of the objective is a sum of one-coordinate terms (Tseng, 2001). The LARS algorithm (Efron et al., 2004) instead traces the exact path, which is piecewise linear in . 6.3. Coordinate Descent describes the general method.
(Degrees of Freedom) The number of nonzero coefficients is an unbiased estimate of the lasso’s degrees of freedom.
Zou, Hastie and Tibshirani (2007) proved this for a fixed . It holds even though the lasso searched over subsets to choose those predictors. Best-subset selection with predictors uses more than degrees of freedom, since the search itself fits the noise. The lasso’s shrinkage lowers the degrees of freedom by about as much as the search raises them. The count can replace in , AIC or BIC to compare fits along the path without cross-validation.
(Sparsity Belongs to the Mode) The Laplace-prior view explains the penalty, but the full posterior under that prior is not sparse.
The lasso returns the posterior mode, which sits exactly at zero for many coefficients. The posterior mean under the same Laplace prior is never exactly zero. The Bayesian lasso of Park and Casella (2008) reports that mean, with credible intervals, and gives up exact selection. Under a continuous prior such as the Laplace, every coefficient has posterior probability zero of being exactly zero. Spike-and-slab priors put a point mass at zero and model sparsity directly.
Derivation
Fix every coefficient except . The objective in is plus constants. Write and , so the function to minimize is . For , the derivative vanishes at , which is positive only when . For , the stationary point is , which is negative only when . At , the subdifferential of is the interval . Zero is optimal when , that is, when . The three cases combine into
With orthonormal columns, and , which gives the orthonormal formula. The same subgradient argument for all coordinates at once gives the optimality conditions in the callout. Setting there shows that zero is optimal exactly when .
Examples
(Easy) A Designed Experiment
An online store tests four page features in a balanced experiment. Each column is scaled to unit length, so . OLS estimates the effects on conversions as .
Compute the lasso and ridge estimates with . The lasso threshold is . Soft-thresholding gives , so the two small features drop out and both survivors move toward zero by . Ridge divides each OLS coefficient by and gives . Ridge keeps all four features. The lasso keeps the largest effect closer to its OLS value, against .
(Medium) Coordinate Descent by Hand
A house-price model uses floor area and number of rooms. Both columns have unit length, their inner product is , and .
Find , run coordinate descent from zero with , and find the at which rooms enters. The largest inner product is , so and floor area enters first. With the threshold is , and the updates are and . The first sweep gives , the second and the third . The fixed point solves and , which gives . Both residual inner products equal there, as the optimality conditions require. With area alone, and the rooms inner product is . Rooms stays out while , that is, for .
(Hard) Two Genes From One Pathway
Two genes have centered columns of unit length and correlation . In one sample their inner products with the outcome are . In a second sample from the same lab they are .
Show that the lasso with selects a different gene in each sample, and compare ridge and the lasso with . The threshold is . In the first sample, gene 1 alone gives . Gene 2's inner product with the residual is , so gene 2 stays out. By symmetry the second sample gives . A change of in the data swaps the selected gene. Ridge with gives and , so both genes stay in with almost equal weight. With the lasso keeps both genes, at in the first sample. Subtracting the two optimality equations gives , so the gap is . The small factor turns a gap of in the data into a gap of in the coefficients. Elastic net adds its ridge weight to that factor and shrinks the gap.
See Also
- 3.2. Regularization, which compares the lasso with ridge and elastic net.
- 3.2.1. Ridge Regression, the smooth counterpart with a closed form.
- 6.3. Coordinate Descent, the algorithm behind most lasso solvers.
- 1.2.2 Maximum a Posteriori Estimation, which derives the Laplace-prior MAP for one coefficient.
- 3.8.1 Bayesian Linear Regression, for the Bayesian treatment of the Laplace prior.
- 2.2 Convex Functions, for the convexity that guarantees a global minimum.