A penalty on the size of the coefficients trades a little bias for a large drop in variance. The lasso penalty |β| sets small coefficients exactly to zero (soft-thresholding); the ridge penalty β² shrinks all of them in proportion; the elastic net mixes the two. Here they are used to predict colorectal cancer from 260 species abundances in stool samples (Zeller et al. 2014), with λ chosen by ten-fold cross-validation.
code/ch12_supervised_learning.R (Figures 12.19 to 12.22, function enet_logistic).