Elastic Net
The elastic net fits a linear model by least squares with a penalty that mixes the lasso and ridge penalties. With standardized predictors and a centered response , it solves
Here is the overall strength and is the mixing weight, as in glmnet. Setting gives the lasso, and gives ridge with penalty . Zou and Hastie (2005) introduced the method with the penalty . The two forms match when and .For the objective is strictly convex, so the solution is unique even when or columns are identical. It has no closed form. Coordinate descent cycles through with the update
where is soft-thresholding and is the partial residual. When , this gives . Three facts set it apart from the lasso:
- Grouping effect: highly correlated predictors get similar coefficients, and identical predictors get identical ones.
- No limit of : it can keep all predictors when , while the lasso keeps at most .
- Lasso on augmented data: it equals the lasso with penalty on stacked over , with zeros appended to .
As a MAP estimate under Gaussian noise of variance , it uses independent priors with density proportional to . This density lies between a Laplace and a Gaussian. Cross-validation tunes and together. Elastic net fits when correlated groups of predictors should be selected together. The lasso suffices when the active predictors are few and weakly correlated, and ridge suffices when no selection is needed.
Software Scales the Loss
glmnet and scikit-learn minimize . Their equals this note’s . scikit-learn calls
alphaand calls the mixing weightl1_ratio.
Intuition
The lasso and ridge fail in opposite ways when predictors are correlated. The lasso keeps one predictor from a correlated group and drops the rest. Small changes in the data can switch its choice. Ridge keeps the whole group but never drops any predictor, even a useless one. Elastic net adds a ridge term to the lasso. The ridge term makes the objective strictly convex, so correlated predictors share the weight. The lasso term still sets weak predictors exactly to zero.
Zou and Hastie (2005) compared the method to a stretchable fishing net that keeps all the big fish. The name refers to selecting a whole correlated group at once, where the lasso would keep one member. In two dimensions the constraint region looks like the lasso’s diamond with its edges bowed outward. The corners on the axes remain, so exact zeros still occur. The curved edges make the region strictly convex, so the error contours touch it at a single point.
Properties
(Grouping Effect) Two same-sign coefficients differ by at most a multiple of , with their predictors’ correlation.
Let the columns have unit length, so is their correlation. If and are nonzero with the same sign, then
As the bound goes to zero, and identical columns get identical coefficients. Zou and Hastie (2005, Theorem 1) give a bound of this form, and the Derivation proves the version above. The lasso has , so it has no such bound. In a model with only these two predictors, both active, the gap equals . The lasso divides by , which is tiny for correlated predictors. Elastic net adds to that denominator.
As falls from 1 to 0, the edges of the region bow outward. The corners on the axes open from but stay sharp for any . With two identical predictors, the lasso puts all the weight on one, and the elastic net splits it equally.
\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{grn}{HTML}{2F9E44}
\newcommand{\rg}[2]{\draw[#1, line cap=round] #2; \draw[#1, line cap=round, xscale=-1] #2; \draw[#1, line cap=round, yscale=-1] #2; \draw[#1, line cap=round, scale=-1] #2;}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\draw[->] (-2.54,0) -- (2.74,0) node[right] {$\beta_1$};
\draw[->] (0,-2.54) -- (0,2.74) node[above] {$\beta_2$};
\node at (0,3.49) {$\alpha\|\beta\|_1 + \frac{1 - \alpha}{2}\|\beta\|_2^2 \le 1$};
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 9.52s = "false", 22.76s = "false", repeats}}}]
\rg{dashed}{(1.45,0.00) -- (0.00,1.45)}
\rg{dashed}{(2.05,0.00) -- (2.05,0.08) -- (2.04,0.16) -- (2.04,0.24) -- (2.03,0.32) -- (2.01,0.40) -- (1.99,0.48) -- (1.97,0.56) -- (1.95,0.63) -- (1.92,0.71) -- (1.89,0.78) -- (1.86,0.86) -- (1.83,0.93) -- (1.79,1.00) -- (1.75,1.07) -- (1.71,1.14) -- (1.66,1.21) -- (1.61,1.27) -- (1.56,1.33) -- (1.51,1.39) -- (1.45,1.45) -- (1.39,1.51) -- (1.33,1.56) -- (1.27,1.61) -- (1.21,1.66) -- (1.14,1.71) -- (1.07,1.75) -- (1.00,1.79) -- (0.93,1.83) -- (0.86,1.86) -- (0.78,1.89) -- (0.71,1.92) -- (0.63,1.95) -- (0.56,1.97) -- (0.48,1.99) -- (0.40,2.01) -- (0.32,2.03) -- (0.24,2.04) -- (0.16,2.04) -- (0.08,2.05) -- (0.00,2.05)}
\draw[->] (4.04,-1.2) -- (8.76,-1.2) node[right] {$t$};
\draw[->] (6.3,-1.2) -- (6.3,1.86);
\node at (6.30,2.66) {penalty on one coefficient};
\node at (6.30,2.21) {$\alpha|t| + \frac{1 - \alpha}{2}t^2$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 16.16s = "true", 22.76s = "true", repeats}}}]
\draw[grn, thick] (-0.41,2.54) -- (2.54,-0.41);
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.52s = "true", 22.76s = "true", repeats}}}]
\rg{cold, very thick}{(1.45,0.00) -- (0.00,1.45)}
\rg{hot, very thick}{(1.79,0.00) -- (1.76,0.07) -- (1.73,0.14) -- (1.69,0.20) -- (1.66,0.26) -- (1.63,0.32) -- (1.59,0.38) -- (1.56,0.44) -- (1.52,0.49) -- (1.49,0.55) -- (1.45,0.60) -- (1.41,0.65) -- (1.38,0.70) -- (1.34,0.75) -- (1.30,0.80) -- (1.26,0.84) -- (1.22,0.89) -- (1.18,0.93) -- (1.14,0.98) -- (1.10,1.02) -- (1.06,1.06) -- (1.02,1.10) -- (0.98,1.14) -- (0.93,1.18) -- (0.89,1.22) -- (0.84,1.26) -- (0.80,1.30) -- (0.75,1.34) -- (0.70,1.38) -- (0.65,1.41) -- (0.60,1.45) -- (0.55,1.49) -- (0.49,1.52) -- (0.44,1.56) -- (0.38,1.59) -- (0.32,1.63) -- (0.26,1.66) -- (0.20,1.69) -- (0.14,1.73) -- (0.07,1.76) -- (0.00,1.79)}
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.32s = "true", 22.76s = "true", repeats}}}]
\draw[grn, dashed] (0.99,2.54) -- (2.54,0.99);
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 19.16s = "true", 22.76s = "true", repeats}}}]
\draw[grn, ultra thick] (-1.09,2.54) -- (2.54,-1.09);
\draw[cold, line width=3.2pt] (1.45,0) -- (0,1.45);
\filldraw[draw=black, fill=hot, thick] (1.06,1.06) circle (3.4pt);
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.52s = "true", 22.76s = "true", repeats}}}]
\node[anchor=south west, inner sep=1pt] at (0.99,2.54) {\footnotesize OLS: $\beta_1 + \beta_2 = 2.43$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 9.52s = "false", 22.76s = "false", repeats}}}]
\node[anchor=west] at (-2.94,-4.29) {\footnotesize dashed: $\alpha = 1$ (diamond) and $\alpha = 0$ (circle), \ red: current $\alpha$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.52s = "true", 22.76s = "true", repeats}}}]
\node[anchor=west] at (-2.94,-4.29) {\footnotesize $x_1 = x_2$, \ blue: lasso ($\alpha = 1$), \ red: elastic net ($\alpha = 0.5$), \ green: RSS contours};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.4s = "false", 22.76s = "false", repeats}}}]
\draw (1.45,0) -- (0.94,0.51);
\draw (1.45,0) -- (0.94,-0.51);
\draw (1.45,0) ++(135.0:0.36) arc[start angle=135.0, end angle=225.0, radius=0.36];
\rg{hot, very thick}{(1.45,0.00) -- (0.00,1.45)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 1.00$: \ crosses the axes at $1.00$, \ corner angle $90^\circ$};
\draw[hot, very thick] (4.14,1.60) -- (4.27,1.43) -- (4.41,1.25) -- (4.54,1.07) -- (4.68,0.90) -- (4.81,0.73) -- (4.95,0.55) -- (5.08,0.38) -- (5.22,0.20) -- (5.35,0.03) -- (5.49,-0.15) -- (5.62,-0.32) -- (5.76,-0.50) -- (5.89,-0.67) -- (6.03,-0.85) -- (6.17,-1.02) -- (6.30,-1.20) -- (6.43,-1.02) -- (6.57,-0.85) -- (6.71,-0.67) -- (6.84,-0.50) -- (6.97,-0.32) -- (7.11,-0.15) -- (7.25,0.03) -- (7.38,0.20) -- (7.51,0.37) -- (7.65,0.55) -- (7.79,0.73) -- (7.92,0.90) -- (8.05,1.08) -- (8.19,1.25) -- (8.32,1.43) -- (8.46,1.60);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 1.00$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha = 1$: the lasso diamond. Its corners on the axes are right angles.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 2.64s = "false", 22.76s = "false", repeats}}}]
\draw (1.49,0) -- (0.99,0.53);
\draw (1.49,0) -- (0.99,-0.53);
\draw (1.49,0) ++(133.4:0.36) arc[start angle=133.4, end angle=226.6, radius=0.36];
\rg{hot, very thick}{(1.49,0.00) -- (1.43,0.06) -- (1.38,0.11) -- (1.34,0.16) -- (1.29,0.20) -- (1.25,0.25) -- (1.21,0.29) -- (1.17,0.33) -- (1.13,0.37) -- (1.10,0.41) -- (1.06,0.44) -- (1.03,0.47) -- (1.00,0.51) -- (0.97,0.54) -- (0.93,0.57) -- (0.90,0.60) -- (0.87,0.63) -- (0.84,0.66) -- (0.81,0.69) -- (0.78,0.72) -- (0.75,0.75) -- (0.72,0.78) -- (0.69,0.81) -- (0.66,0.84) -- (0.63,0.87) -- (0.60,0.90) -- (0.57,0.93) -- (0.54,0.97) -- (0.51,1.00) -- (0.47,1.03) -- (0.44,1.06) -- (0.41,1.10) -- (0.37,1.13) -- (0.33,1.17) -- (0.29,1.21) -- (0.25,1.25) -- (0.20,1.29) -- (0.16,1.34) -- (0.11,1.38) -- (0.06,1.43) -- (0.00,1.49)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.95$: \ crosses the axes at $1.03$, \ corner angle $93^\circ$};
\draw[hot, very thick] (4.14,1.57) -- (4.27,1.39) -- (4.41,1.21) -- (4.54,1.03) -- (4.68,0.86) -- (4.81,0.68) -- (4.95,0.50) -- (5.08,0.33) -- (5.22,0.16) -- (5.35,-0.02) -- (5.49,-0.19) -- (5.62,-0.36) -- (5.76,-0.53) -- (5.89,-0.70) -- (6.03,-0.87) -- (6.17,-1.03) -- (6.30,-1.20) -- (6.43,-1.03) -- (6.57,-0.87) -- (6.71,-0.70) -- (6.84,-0.53) -- (6.97,-0.36) -- (7.11,-0.19) -- (7.25,-0.02) -- (7.38,0.16) -- (7.51,0.33) -- (7.65,0.50) -- (7.79,0.68) -- (7.92,0.86) -- (8.05,1.03) -- (8.19,1.21) -- (8.32,1.39) -- (8.46,1.57);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.95$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls. The squared term bends the edges outward.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.64s = "true", 2.88s = "false", 22.76s = "false", repeats}}}]
\draw (1.58,0) -- (1.12,0.56);
\draw (1.58,0) -- (1.12,-0.56);
\draw (1.58,0) ++(129.1:0.36) arc[start angle=129.1, end angle=230.9, radius=0.36];
\rg{hot, very thick}{(1.58,0.00) -- (1.53,0.06) -- (1.48,0.12) -- (1.44,0.17) -- (1.39,0.22) -- (1.35,0.27) -- (1.31,0.31) -- (1.27,0.36) -- (1.23,0.40) -- (1.20,0.44) -- (1.16,0.48) -- (1.13,0.52) -- (1.09,0.56) -- (1.06,0.59) -- (1.03,0.63) -- (0.99,0.66) -- (0.96,0.70) -- (0.93,0.73) -- (0.89,0.76) -- (0.86,0.80) -- (0.83,0.83) -- (0.80,0.86) -- (0.76,0.89) -- (0.73,0.93) -- (0.70,0.96) -- (0.66,0.99) -- (0.63,1.03) -- (0.59,1.06) -- (0.56,1.09) -- (0.52,1.13) -- (0.48,1.16) -- (0.44,1.20) -- (0.40,1.23) -- (0.36,1.27) -- (0.31,1.31) -- (0.27,1.35) -- (0.22,1.39) -- (0.17,1.44) -- (0.12,1.48) -- (0.06,1.53) -- (0.00,1.58)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.82$: \ crosses the axes at $1.09$, \ corner angle $102^\circ$};
\draw[hot, very thick] (4.14,1.50) -- (4.27,1.31) -- (4.41,1.12) -- (4.54,0.93) -- (4.68,0.75) -- (4.81,0.57) -- (4.95,0.40) -- (5.08,0.22) -- (5.22,0.05) -- (5.35,-0.12) -- (5.49,-0.28) -- (5.62,-0.44) -- (5.76,-0.60) -- (5.89,-0.75) -- (6.03,-0.91) -- (6.17,-1.05) -- (6.30,-1.20) -- (6.43,-1.05) -- (6.57,-0.91) -- (6.71,-0.75) -- (6.84,-0.60) -- (6.97,-0.44) -- (7.11,-0.28) -- (7.25,-0.12) -- (7.38,0.05) -- (7.51,0.22) -- (7.65,0.40) -- (7.79,0.57) -- (7.92,0.75) -- (8.05,0.93) -- (8.19,1.12) -- (8.32,1.31) -- (8.46,1.50);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.82$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls. The squared term bends the edges outward.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.88s = "true", 3.12s = "false", 22.76s = "false", repeats}}}]
\draw (1.68,0) -- (1.29,0.61);
\draw (1.68,0) -- (1.29,-0.61);
\draw (1.68,0) ++(122.7:0.36) arc[start angle=122.7, end angle=237.3, radius=0.36];
\rg{hot, very thick}{(1.68,0.00) -- (1.64,0.06) -- (1.60,0.13) -- (1.56,0.18) -- (1.52,0.24) -- (1.48,0.29) -- (1.44,0.35) -- (1.40,0.39) -- (1.36,0.44) -- (1.33,0.49) -- (1.29,0.53) -- (1.25,0.58) -- (1.22,0.62) -- (1.18,0.66) -- (1.15,0.70) -- (1.11,0.74) -- (1.07,0.78) -- (1.04,0.82) -- (1.00,0.86) -- (0.97,0.89) -- (0.93,0.93) -- (0.89,0.97) -- (0.86,1.00) -- (0.82,1.04) -- (0.78,1.07) -- (0.74,1.11) -- (0.70,1.15) -- (0.66,1.18) -- (0.62,1.22) -- (0.58,1.25) -- (0.53,1.29) -- (0.49,1.33) -- (0.44,1.36) -- (0.39,1.40) -- (0.35,1.44) -- (0.29,1.48) -- (0.24,1.52) -- (0.18,1.56) -- (0.13,1.60) -- (0.06,1.64) -- (0.00,1.68)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.68$: \ crosses the axes at $1.16$, \ corner angle $115^\circ$};
\draw[hot, very thick] (4.14,1.42) -- (4.27,1.21) -- (4.41,1.01) -- (4.54,0.82) -- (4.68,0.63) -- (4.81,0.44) -- (4.95,0.27) -- (5.08,0.09) -- (5.22,-0.07) -- (5.35,-0.23) -- (5.49,-0.39) -- (5.62,-0.54) -- (5.76,-0.68) -- (5.89,-0.82) -- (6.03,-0.95) -- (6.17,-1.08) -- (6.30,-1.20) -- (6.43,-1.08) -- (6.57,-0.95) -- (6.71,-0.82) -- (6.84,-0.68) -- (6.97,-0.54) -- (7.11,-0.39) -- (7.25,-0.23) -- (7.38,-0.07) -- (7.51,0.09) -- (7.65,0.27) -- (7.79,0.44) -- (7.92,0.63) -- (8.05,0.82) -- (8.19,1.01) -- (8.32,1.21) -- (8.46,1.42);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.68$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls. The squared term bends the edges outward.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.12s = "true", 3.36s = "false", 22.76s = "false", repeats}}}]
\draw (1.76,0) -- (1.43,0.65);
\draw (1.76,0) -- (1.43,-0.65);
\draw (1.76,0) ++(116.7:0.36) arc[start angle=116.7, end angle=243.3, radius=0.36];
\rg{hot, very thick}{(1.76,0.00) -- (1.72,0.07) -- (1.69,0.13) -- (1.65,0.20) -- (1.62,0.26) -- (1.58,0.31) -- (1.55,0.37) -- (1.51,0.43) -- (1.47,0.48) -- (1.44,0.53) -- (1.40,0.58) -- (1.37,0.63) -- (1.33,0.68) -- (1.29,0.72) -- (1.25,0.77) -- (1.22,0.81) -- (1.18,0.86) -- (1.14,0.90) -- (1.10,0.94) -- (1.06,0.98) -- (1.02,1.02) -- (0.98,1.06) -- (0.94,1.10) -- (0.90,1.14) -- (0.86,1.18) -- (0.81,1.22) -- (0.77,1.25) -- (0.72,1.29) -- (0.68,1.33) -- (0.63,1.37) -- (0.58,1.40) -- (0.53,1.44) -- (0.48,1.47) -- (0.43,1.51) -- (0.37,1.55) -- (0.31,1.58) -- (0.26,1.62) -- (0.20,1.65) -- (0.13,1.69) -- (0.07,1.72) -- (0.00,1.76)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.55$: \ crosses the axes at $1.21$, \ corner angle $127^\circ$};
\draw[hot, very thick] (4.14,1.35) -- (4.27,1.13) -- (4.41,0.92) -- (4.54,0.72) -- (4.68,0.52) -- (4.81,0.34) -- (4.95,0.16) -- (5.08,-0.01) -- (5.22,-0.18) -- (5.35,-0.33) -- (5.49,-0.48) -- (5.62,-0.62) -- (5.76,-0.75) -- (5.89,-0.87) -- (6.03,-0.99) -- (6.17,-1.10) -- (6.30,-1.20) -- (6.43,-1.10) -- (6.57,-0.99) -- (6.71,-0.87) -- (6.84,-0.75) -- (6.97,-0.62) -- (7.11,-0.48) -- (7.25,-0.33) -- (7.38,-0.18) -- (7.51,-0.01) -- (7.65,0.16) -- (7.79,0.34) -- (7.92,0.52) -- (8.05,0.72) -- (8.19,0.92) -- (8.32,1.13) -- (8.46,1.35);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.55$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls. The squared term bends the edges outward.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.36s = "true", 6.16s = "false", 22.76s = "false", repeats}}}]
\draw (1.79,0) -- (1.50,0.66);
\draw (1.79,0) -- (1.50,-0.66);
\draw (1.79,0) ++(114.1:0.36) arc[start angle=114.1, end angle=245.9, radius=0.36];
\rg{hot, very thick}{(1.79,0.00) -- (1.76,0.07) -- (1.73,0.14) -- (1.69,0.20) -- (1.66,0.26) -- (1.63,0.32) -- (1.59,0.38) -- (1.56,0.44) -- (1.52,0.49) -- (1.49,0.55) -- (1.45,0.60) -- (1.41,0.65) -- (1.38,0.70) -- (1.34,0.75) -- (1.30,0.80) -- (1.26,0.84) -- (1.22,0.89) -- (1.18,0.93) -- (1.14,0.98) -- (1.10,1.02) -- (1.06,1.06) -- (1.02,1.10) -- (0.98,1.14) -- (0.93,1.18) -- (0.89,1.22) -- (0.84,1.26) -- (0.80,1.30) -- (0.75,1.34) -- (0.70,1.38) -- (0.65,1.41) -- (0.60,1.45) -- (0.55,1.49) -- (0.49,1.52) -- (0.44,1.56) -- (0.38,1.59) -- (0.32,1.63) -- (0.26,1.66) -- (0.20,1.69) -- (0.14,1.73) -- (0.07,1.76) -- (0.00,1.79)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.50$: \ crosses the axes at $1.24$, \ corner angle $132^\circ$};
\draw[hot, very thick] (4.14,1.32) -- (4.27,1.10) -- (4.41,0.88) -- (4.54,0.68) -- (4.68,0.48) -- (4.81,0.29) -- (4.95,0.11) -- (5.08,-0.06) -- (5.22,-0.22) -- (5.35,-0.37) -- (5.49,-0.52) -- (5.62,-0.65) -- (5.76,-0.78) -- (5.89,-0.90) -- (6.03,-1.01) -- (6.17,-1.11) -- (6.30,-1.20) -- (6.43,-1.11) -- (6.57,-1.01) -- (6.71,-0.90) -- (6.84,-0.78) -- (6.97,-0.65) -- (7.11,-0.52) -- (7.25,-0.37) -- (7.38,-0.22) -- (7.51,-0.06) -- (7.65,0.11) -- (7.79,0.29) -- (7.92,0.48) -- (8.05,0.68) -- (8.19,0.88) -- (8.32,1.10) -- (8.46,1.32);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.50$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha = 0.5$: the corners open but stay sharp. The penalty still has a kink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.16s = "true", 6.4s = "false", 22.76s = "false", repeats}}}]
\draw (1.82,0) -- (1.56,0.67);
\draw (1.82,0) -- (1.56,-0.67);
\draw (1.82,0) ++(111.4:0.36) arc[start angle=111.4, end angle=248.6, radius=0.36];
\rg{hot, very thick}{(1.82,0.00) -- (1.80,0.07) -- (1.77,0.14) -- (1.73,0.21) -- (1.70,0.27) -- (1.67,0.33) -- (1.64,0.39) -- (1.60,0.45) -- (1.57,0.51) -- (1.53,0.57) -- (1.50,0.62) -- (1.46,0.67) -- (1.42,0.73) -- (1.39,0.78) -- (1.35,0.83) -- (1.31,0.87) -- (1.27,0.92) -- (1.23,0.97) -- (1.19,1.01) -- (1.15,1.06) -- (1.10,1.10) -- (1.06,1.15) -- (1.01,1.19) -- (0.97,1.23) -- (0.92,1.27) -- (0.87,1.31) -- (0.83,1.35) -- (0.78,1.39) -- (0.73,1.42) -- (0.67,1.46) -- (0.62,1.50) -- (0.57,1.53) -- (0.51,1.57) -- (0.45,1.60) -- (0.39,1.64) -- (0.33,1.67) -- (0.27,1.70) -- (0.21,1.73) -- (0.14,1.77) -- (0.07,1.80) -- (0.00,1.82)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.45$: \ crosses the axes at $1.26$, \ corner angle $137^\circ$};
\draw[hot, very thick] (4.14,1.29) -- (4.27,1.06) -- (4.41,0.84) -- (4.54,0.64) -- (4.68,0.44) -- (4.81,0.25) -- (4.95,0.07) -- (5.08,-0.10) -- (5.22,-0.26) -- (5.35,-0.41) -- (5.49,-0.56) -- (5.62,-0.69) -- (5.76,-0.81) -- (5.89,-0.92) -- (6.03,-1.02) -- (6.17,-1.12) -- (6.30,-1.20) -- (6.43,-1.12) -- (6.57,-1.02) -- (6.71,-0.92) -- (6.84,-0.81) -- (6.97,-0.69) -- (7.11,-0.56) -- (7.25,-0.41) -- (7.38,-0.26) -- (7.51,-0.10) -- (7.65,0.07) -- (7.79,0.25) -- (7.92,0.44) -- (8.05,0.64) -- (8.19,0.84) -- (8.32,1.06) -- (8.46,1.29);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.45$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls further. The corners keep opening.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.4s = "true", 6.64s = "false", 22.76s = "false", repeats}}}]
\draw (1.89,0) -- (1.71,0.70);
\draw (1.89,0) -- (1.71,-0.70);
\draw (1.89,0) ++(105.0:0.36) arc[start angle=105.0, end angle=255.0, radius=0.36];
\rg{hot, very thick}{(1.89,0.00) -- (1.87,0.07) -- (1.85,0.15) -- (1.83,0.22) -- (1.80,0.29) -- (1.77,0.35) -- (1.74,0.42) -- (1.71,0.48) -- (1.68,0.55) -- (1.65,0.61) -- (1.61,0.67) -- (1.58,0.73) -- (1.54,0.78) -- (1.50,0.84) -- (1.46,0.90) -- (1.42,0.95) -- (1.38,1.00) -- (1.34,1.05) -- (1.29,1.10) -- (1.25,1.15) -- (1.20,1.20) -- (1.15,1.25) -- (1.10,1.29) -- (1.05,1.34) -- (1.00,1.38) -- (0.95,1.42) -- (0.90,1.46) -- (0.84,1.50) -- (0.78,1.54) -- (0.73,1.58) -- (0.67,1.61) -- (0.61,1.65) -- (0.55,1.68) -- (0.48,1.71) -- (0.42,1.74) -- (0.35,1.77) -- (0.29,1.80) -- (0.22,1.83) -- (0.15,1.85) -- (0.07,1.87) -- (0.00,1.89)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.32$: \ crosses the axes at $1.31$, \ corner angle $150^\circ$};
\draw[hot, very thick] (4.14,1.22) -- (4.27,0.98) -- (4.41,0.75) -- (4.54,0.54) -- (4.68,0.33) -- (4.81,0.14) -- (4.95,-0.04) -- (5.08,-0.21) -- (5.22,-0.37) -- (5.35,-0.51) -- (5.49,-0.65) -- (5.62,-0.77) -- (5.76,-0.88) -- (5.89,-0.98) -- (6.03,-1.06) -- (6.17,-1.14) -- (6.30,-1.20) -- (6.43,-1.14) -- (6.57,-1.06) -- (6.71,-0.98) -- (6.84,-0.88) -- (6.97,-0.77) -- (7.11,-0.65) -- (7.25,-0.51) -- (7.38,-0.37) -- (7.51,-0.21) -- (7.65,-0.04) -- (7.79,0.14) -- (7.92,0.33) -- (8.05,0.54) -- (8.19,0.75) -- (8.32,0.98) -- (8.46,1.22);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.32$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls further. The corners keep opening.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.64s = "true", 6.88s = "false", 22.76s = "false", repeats}}}]
\draw (1.97,0) -- (1.87,0.72);
\draw (1.97,0) -- (1.87,-0.72);
\draw (1.97,0) ++(97.7:0.36) arc[start angle=97.7, end angle=262.3, radius=0.36];
\rg{hot, very thick}{(1.97,0.00) -- (1.96,0.08) -- (1.94,0.15) -- (1.93,0.23) -- (1.91,0.30) -- (1.89,0.38) -- (1.86,0.45) -- (1.84,0.52) -- (1.81,0.59) -- (1.78,0.66) -- (1.75,0.72) -- (1.71,0.79) -- (1.68,0.85) -- (1.64,0.92) -- (1.60,0.98) -- (1.55,1.04) -- (1.51,1.10) -- (1.47,1.15) -- (1.42,1.21) -- (1.37,1.26) -- (1.32,1.32) -- (1.26,1.37) -- (1.21,1.42) -- (1.15,1.47) -- (1.10,1.51) -- (1.04,1.55) -- (0.98,1.60) -- (0.92,1.64) -- (0.85,1.68) -- (0.79,1.71) -- (0.72,1.75) -- (0.66,1.78) -- (0.59,1.81) -- (0.52,1.84) -- (0.45,1.86) -- (0.38,1.89) -- (0.30,1.91) -- (0.23,1.93) -- (0.15,1.94) -- (0.08,1.96) -- (0.00,1.97)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.18$: \ crosses the axes at $1.36$, \ corner angle $165^\circ$};
\draw[hot, very thick] (4.14,1.14) -- (4.27,0.88) -- (4.41,0.64) -- (4.54,0.42) -- (4.68,0.21) -- (4.81,0.01) -- (4.95,-0.17) -- (5.08,-0.34) -- (5.22,-0.49) -- (5.35,-0.63) -- (5.49,-0.76) -- (5.62,-0.87) -- (5.76,-0.96) -- (5.89,-1.04) -- (6.03,-1.11) -- (6.17,-1.16) -- (6.30,-1.20) -- (6.43,-1.16) -- (6.57,-1.11) -- (6.71,-1.04) -- (6.84,-0.96) -- (6.97,-0.87) -- (7.11,-0.76) -- (7.25,-0.63) -- (7.38,-0.49) -- (7.51,-0.34) -- (7.65,-0.17) -- (7.79,0.01) -- (7.92,0.21) -- (8.05,0.42) -- (8.19,0.64) -- (8.32,0.88) -- (8.46,1.14);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.18$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls further. The corners keep opening.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.88s = "true", 7.12s = "false", 22.76s = "false", repeats}}}]
\draw (2.03,0) -- (2.00,0.72);
\draw (2.03,0) -- (2.00,-0.72);
\draw (2.03,0) ++(92.2:0.36) arc[start angle=92.2, end angle=267.8, radius=0.36];
\rg{hot, very thick}{(2.03,0.00) -- (2.02,0.08) -- (2.02,0.16) -- (2.01,0.24) -- (1.99,0.32) -- (1.98,0.39) -- (1.96,0.47) -- (1.93,0.55) -- (1.91,0.62) -- (1.88,0.69) -- (1.85,0.77) -- (1.82,0.84) -- (1.78,0.91) -- (1.75,0.98) -- (1.70,1.04) -- (1.66,1.11) -- (1.62,1.17) -- (1.57,1.24) -- (1.52,1.30) -- (1.47,1.36) -- (1.41,1.41) -- (1.36,1.47) -- (1.30,1.52) -- (1.24,1.57) -- (1.17,1.62) -- (1.11,1.66) -- (1.04,1.70) -- (0.98,1.75) -- (0.91,1.78) -- (0.84,1.82) -- (0.77,1.85) -- (0.69,1.88) -- (0.62,1.91) -- (0.55,1.93) -- (0.47,1.96) -- (0.39,1.98) -- (0.32,1.99) -- (0.24,2.01) -- (0.16,2.02) -- (0.08,2.02) -- (0.00,2.03)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.05$: \ crosses the axes at $1.40$, \ corner angle $176^\circ$};
\draw[hot, very thick] (4.14,1.07) -- (4.27,0.80) -- (4.41,0.55) -- (4.54,0.32) -- (4.68,0.10) -- (4.81,-0.10) -- (4.95,-0.28) -- (5.08,-0.45) -- (5.22,-0.60) -- (5.35,-0.73) -- (5.49,-0.85) -- (5.62,-0.95) -- (5.76,-1.03) -- (5.89,-1.10) -- (6.03,-1.15) -- (6.17,-1.18) -- (6.30,-1.20) -- (6.43,-1.18) -- (6.57,-1.15) -- (6.71,-1.10) -- (6.84,-1.03) -- (6.97,-0.95) -- (7.11,-0.85) -- (7.25,-0.73) -- (7.38,-0.60) -- (7.51,-0.45) -- (7.65,-0.28) -- (7.79,-0.10) -- (7.92,0.10) -- (8.05,0.32) -- (8.19,0.55) -- (8.32,0.80) -- (8.46,1.07);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.05$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha$ falls further. The corners keep opening.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.12s = "true", 9.52s = "false", 22.76s = "false", repeats}}}]
\draw (2.05,0) -- (2.05,0.72);
\draw (2.05,0) -- (2.05,-0.72);
\draw (2.05,0) ++(90.0:0.36) arc[start angle=90.0, end angle=270.0, radius=0.36];
\rg{hot, very thick}{(2.05,0.00) -- (2.05,0.08) -- (2.04,0.16) -- (2.04,0.24) -- (2.03,0.32) -- (2.01,0.40) -- (1.99,0.48) -- (1.97,0.56) -- (1.95,0.63) -- (1.92,0.71) -- (1.89,0.78) -- (1.86,0.86) -- (1.83,0.93) -- (1.79,1.00) -- (1.75,1.07) -- (1.71,1.14) -- (1.66,1.21) -- (1.61,1.27) -- (1.56,1.33) -- (1.51,1.39) -- (1.45,1.45) -- (1.39,1.51) -- (1.33,1.56) -- (1.27,1.61) -- (1.21,1.66) -- (1.14,1.71) -- (1.07,1.75) -- (1.00,1.79) -- (0.93,1.83) -- (0.86,1.86) -- (0.78,1.89) -- (0.71,1.92) -- (0.63,1.95) -- (0.56,1.97) -- (0.48,1.99) -- (0.40,2.01) -- (0.32,2.03) -- (0.24,2.04) -- (0.16,2.04) -- (0.08,2.05) -- (0.00,2.05)}
\node[anchor=west] at (-2.94,-3.09) {$\alpha = 0.00$: \ crosses the axes at $1.41$, \ corner angle $180^\circ$};
\draw[hot, very thick] (4.14,1.04) -- (4.27,0.77) -- (4.41,0.52) -- (4.54,0.28) -- (4.68,0.06) -- (4.81,-0.14) -- (4.95,-0.32) -- (5.08,-0.49) -- (5.22,-0.64) -- (5.35,-0.77) -- (5.49,-0.88) -- (5.62,-0.98) -- (5.76,-1.06) -- (5.89,-1.12) -- (6.03,-1.17) -- (6.17,-1.19) -- (6.30,-1.20) -- (6.43,-1.19) -- (6.57,-1.17) -- (6.71,-1.12) -- (6.84,-1.06) -- (6.97,-0.98) -- (7.11,-0.88) -- (7.25,-0.77) -- (7.38,-0.64) -- (7.51,-0.49) -- (7.65,-0.32) -- (7.79,-0.14) -- (7.92,0.06) -- (8.05,0.28) -- (8.19,0.51) -- (8.32,0.77) -- (8.46,1.04);
\node[anchor=west] at (4.14,-1.90) {\footnotesize slope just right of $0$: $\alpha = 0.00$};
\node[anchor=west] at (-2.94,-3.74) {$\alpha = 0$: the ridge circle. The kink and the corners are gone.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.52s = "true", 12.32s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (0.99,2.54) -- (2.54,0.99);
\node[anchor=west] at (-2.94,-3.74) {Now $x_1 = x_2$. RSS depends only on $\beta_1 + \beta_2$. Its contours are lines.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.32s = "true", 12.58s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (0.77,2.54) -- (2.54,0.77);
\node[anchor=west] at (-2.94,-3.74) {The RSS contour line slides toward the regions.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.58s = "true", 12.84s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (0.29,2.54) -- (2.54,0.29);
\node[anchor=west] at (-2.94,-3.74) {The RSS contour line slides toward the regions.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.84s = "true", 13.1s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (-0.20,2.54) -- (2.54,-0.20);
\node[anchor=west] at (-2.94,-3.74) {The RSS contour line slides toward the regions.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 13.1s = "true", 15.9s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (-0.41,2.54) -- (2.54,-0.41);
\filldraw[draw=black, fill=hot, thick] (1.06,1.06) circle (3.4pt);
\node[anchor=west] at (-2.94,-3.74) {It touches the $\alpha = 0.5$ region at one point, $(0.73, 0.73)$. The split is equal.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 15.9s = "true", 16.16s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (-0.75,2.54) -- (2.54,-0.75);
\filldraw[draw=black, fill=hot, thick] (1.06,1.06) circle (3.4pt);
\node[anchor=west] at (-2.94,-3.74) {The line slides on toward the diamond.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 16.16s = "true", 19.16s = "false", 22.76s = "false", repeats}}}]
\draw[grn, ultra thick] (-1.09,2.54) -- (2.54,-1.09);
\draw[cold, line width=3.2pt] (1.45,0) -- (0,1.45);
\filldraw[draw=black, fill=hot, thick] (1.06,1.06) circle (3.4pt);
\node[anchor=west] at (-2.94,-3.74) {It meets the diamond along a whole edge. Each point on it is a lasso solution.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 19.16s = "true", 22.76s = "true", repeats}}}]
\draw (3.90,-1.3) -- (8.70,-1.3);
\filldraw[draw=black, fill=cold] (4.12,-1.3) rectangle (4.68,0.99);
\node[above] at (4.40,0.99) {\footnotesize $1.43$};
\node[below] at (4.40,-1.3) {\footnotesize $\beta_1$};
\node[above] at (5.15,-1.30) {\footnotesize $0.00$};
\node[below] at (5.15,-1.3) {\footnotesize $\beta_2$};
\node at (4.78,-2.05) {lasso};
\filldraw[draw=black, fill=hot] (6.42,-1.3) rectangle (6.98,-0.07);
\node[above] at (6.70,-0.07) {\footnotesize $0.77$};
\node[below] at (6.70,-1.3) {\footnotesize $\beta_1$};
\filldraw[draw=black, fill=hot] (7.17,-1.3) rectangle (7.73,-0.07);
\node[above] at (7.45,-0.07) {\footnotesize $0.77$};
\node[below] at (7.45,-1.3) {\footnotesize $\beta_2$};
\node at (7.08,-2.05) {elastic net};
\node at (6.30,2.21) {fitted by coordinate descent};
\node at (6.30,1.76) {\footnotesize $\lambda = 1$, \ elastic net $\alpha = 0.5$};
\node[anchor=west] at (-2.94,-3.74) {The lasso puts all the weight on $x_1$. The elastic net splits it equally.};
\end{scope}
\end{tikzpicture}
\end{document}(No Limit of ) The augmented design has rows, so the lasso inside elastic net can keep all predictors.
The lasso keeps at most predictors. The augmented matrix stacks below , so its rank is for any . The lasso limit then becomes , which removes the cap. This matters when the outcome depends on more predictors than there are samples. A gene-expression study with patients and a pathway of co-regulated genes is a typical case.
(Double Shrinkage) The plain elastic net shrinks twice, by soft-thresholding and by the ridge factor, so Zou and Hastie rescale it.
In an orthonormal design, the update divides the lasso estimate by . Zou and Hastie found that this extra shrinkage hurt prediction. They called the estimator above the naive elastic net and defined the elastic net as for unit-length columns. In an orthonormal design, the rescaled estimate equals the lasso with penalty . With correlated predictors, it keeps the grouping effect. glmnet and scikit-learn return the naive estimate without the rescaling. To get Zou and Hastie’s estimate, standardize the columns to unit length and multiply the result by .
(Tuning Two Hyperparameters) Cross-validation searches a small grid of values and a full path for each, all on shared folds.
For each in a grid such as , glmnet computes the whole path with warm starts. Every must use the same fold assignment. Otherwise the differences between values mix with the noise from different splits. Small behaves like ridge and keeps many predictors, while near behaves like the lasso. Friedman, Hastie and Tibshirani (2010) note that for a small acts much like the lasso. It also removes the erratic behavior of the lasso under extreme correlation. The CV error often changes little across . In that case, choose by the number of predictors you want to keep.
Derivation
The augmented-data reduction follows from the squared length of a stacked residual. Let and . Then
so adding to both sides gives the elastic-net objective. The coordinate update follows from the lasso update applied to . Column of has squared length . Its inner product with the augmented partial residual is , since the extra row for meets a zero response.
For the grouping bound, take and nonzero with the same sign . Write . Setting the derivative in to zero gives
and the same holds for . Subtracting the two equations cancels and leaves . By Cauchy-Schwarz, . Unit-length columns give . The objective at is at most its value at , so . Combining these gives the bound.
Examples
(Easy) An Orthogonal Field Trial
A crop trial tests three fertilizer additives in a balanced design. Each column is scaled to unit length, so . OLS estimates the effects on yield as .
Compute the naive elastic net with and , and then its rescaled version. The two forms give and . Soft-thresholding at gives , and dividing by gives . No coefficient is zero, because each OLS value exceeds in size. Rescaling by returns , which is the lasso with . With orthogonal predictors, the ridge part adds only shrinkage, and the grouping effect has nothing to act on.
(Medium) Two Sensors on One Street
Two air-quality sensors on the same street have centered columns of unit length and correlation . Their inner products with the outcome are .
Compare the lasso with and against elastic net with and . The lasso with keeps only sensor 1, at . Sensor 2's residual inner product is , so it stays out. The lasso with keeps both, at . When both are active, subtracting their optimality equations gives . The lasso has , so its gap is . Elastic net has and , so its gap is . Adding the two equations gives , so the sum is . Elastic net therefore returns , close to an even split.
(Hard) Three Biomarkers, Two Patients
A pilot study measures three biomarkers on two patients. The columns have unit length, with , and , and . Biomarker 3 equals .
Which biomarkers do the lasso with and elastic net with , keep? The inner products are , so biomarker 3 enters first, at . The lasso with returns . Its residual is , so the inner products with columns 1 and 3 equal , and column 2 gives . The lasso keeps two biomarkers, the most it can with . As it tends to , the exact fit with the smallest norm, still with two nonzeros. Elastic net has and . Coordinate descent returns , so all three biomarkers stay in. Its augmented design has rows and rank , so the cap of no longer applies.
See Also
- 3.2. Regularization, which compares the three penalties and gives the decision rule.
- 3.2.2. Lasso, the case and the source of the soft-thresholding update.
- 3.2.1. Ridge Regression, the case and the source of the augmented-data view.
- 6.3. Coordinate Descent, the standard solver.
- 2.3.2. Cross-Validation, for tuning and on shared folds.
- 3.8.1 Bayesian Linear Regression, for the Gaussian and Laplace priors that this prior mixes.