Contents
06Regularization paths: correlated features and the elastic net
6.1Paths on real data
A regularization path shows every weight as a function of \lambda. Figure 4 computes both paths for the diabetes data of Efron et al. (2004): 442 patients, 10 baseline variables (age, sex, body mass index bmi, average blood pressure bp and six blood serum measurements s1–s6), and a measure of disease progression one year later as the target. The features are standardized, so the weights are comparable.
lasso_path, whose penalty \alpha corresponds to \lambda=2n\alpha in (1): the weights reach zero one at a time, the last one (bmi) at \alpha=45.16. Data: scikit-learn diabetes data (Efron et al., 2004; Pedregosa et al., 2011); paths computed for this tutorial, as in the companion video.The ridge paths (Figure 4a) shrink all ten weights continuously toward zero; even at \lambda=10^5 the largest weight is still 0.197. The lasso paths (Figure 4b) are piecewise linear and hit zero one after another, so every \lambda selects a subset of features. Read from right to left, with decreasing penalty, the features enter in the order bmi, s5, bp, s3, sex, s6, s1, s4, s2, age. By (11) the first is the feature most correlated with y: x_{\cdot j}^\top y is 19{,}961 for bmi and 19{,}261 for s5, and the path leaves zero at \lambda_{\max}=2\cdot19{,}961=39{,}921, which is \alpha=\lambda_{\max}/(2n)=45.16 on scikit-learn’s scale.
6.2Correlated features
The serum measurements s1 and s2 have correlation 0.897. Least squares gives them large weights of opposite signs, -37.68 and 22.68, the same cancelling pattern as in Worked example 2. Ridge pulls both toward zero together. The lasso behaves differently: when two features carry nearly the same information it tends to pick one of them, somewhat arbitrarily, and drop the other, as in Worked example 4. The selected one can change with a small change in the data, which makes lasso feature selection unstable for groups of correlated features, a classic point of criticism (Zou and Hastie, 2005). The prostate cancer data, 97 men with 8 clinical predictors of the log PSA level, show how fragile “the selected features” can be: the lasso keeps 3 of the predictors in Tibshirani (1996), 4 in Hastie et al. (2009, Table 3.3) and 5 in Zou and Hastie (2005, Table 1), because the three analyses split the data and choose \lambda differently. Two more limitations are worth knowing: when p>n the lasso selects at most n features before it saturates (Efron et al., 2004; Zou and Hastie, 2005), and it recovers the truly relevant features only under conditions that limit how strongly irrelevant features may correlate with relevant ones (Zhao and Yu, 2006).
6.3The elastic net
Zou and Hastie (2005) proposed to combine both penalties,
The L1 part produces zeros; the L2 part makes the problem strictly convex, so the solution is unique, and it creates a grouping effect: highly correlated features get similar weights and enter or leave the model together. In the budget picture, the elastic-net ball has corners on the axes like the diamond, but curved edges like the disc. Coordinate descent still works: the update becomes w_j\leftarrow S_{\lambda_1/2}(z_j)/(A_{jj}+\lambda_2).
Worked example 6. For the correlated pair of Worked example 4 with \lambda_1=\lambda_2=0.1, coordinate descent converges to (0.541,\;0.359): like ridge, both near-duplicates are kept with similar positive weights; like the lasso, a feature with a weaker correlation than the threshold would still be set to zero. Since both weights are positive at the solution, it satisfies (A+0.1I)w=b-0.05\,(1,1), which can be checked by hand.
A real case: genes. Zou and Hastie (2005) applied the elastic net to a classic leukemia data set with 7{,}129 gene-expression measurements on 72 patients, 38 for training and 34 for testing. It selected 45 genes, made 3 errors in ten-fold cross-validation on the training patients and none on the 34 test patients. The lasso could not have done this: with 38 training samples it can select at most 38 genes.
Pause and think. You have p=10{,}000 gene-expression features, n=100 patients, and genes act in correlated pathways. Lasso, ridge or elastic net?
Show the answer
The elastic net. The lasso would select at most 100 genes and pick one gene per correlated pathway almost at random; ridge would keep all 10{,}000 and give no selection. The elastic net selects and keeps correlated genes together.