# The Lasso¶

## Suggested Prerequisites¶

## Notes¶

The acronym stands for

**Least Absolute Shrinkage and Selection Operator**Helps to reduce

**overfitting**by reducing model variance through the addition of**shrinkage**to zero for selective coefficients.Can be useful in

**feature selection**tasks due to its automated feature selection property

## Loss Function and Optimization Problem¶

The associated loss function for **the Lasso** modifies the OLS loss function through the addition of an \(\mathbf{L}_1\) penalty controlled by a tuning parameter, \(\lambda\):

Using this function to formulate a *least-squares* optimization problem yields:

No closed-form solution exists in this case since the addition of the \(\mathbf{L}_1\) penalty adds a non-smooth, absolute component to the loss function rendering it no longer continuously differentiable. Thus, a discrete optimization technique is required to solve for model coefficient estimates. Many algorithms can be utilized for this purpose such as * LARS* (Least Angle Regression) and

*. Coordinate Descent seems to be the most favored algorithm currently and used in the popular packages*

**Forwards Stepwise Regression***in Python and*

**Scikit-Learn***in R.*

**GLMNET**### Pathwise Coordinate Descent¶

Here, all features should be standardized to have zero mean and unit variance. A \(p+1\) length coefficient vector is then initialized to zero. Cycles are run across all coefficients until convergence when the values stabilize within a certain tolerance. For every cycle, across each coefficient, a coefficient update is found.

The simplest form of update calculates the simple least-squares coefficient value using the partial residuals across all other features in the design matrix and subsequently applies the soft-thresholding operator with the tuning parameter penalty as:

where \(\mathbf{S}\) is the soft-thresholding operator and \(\beta_j^*\) is the update as calculated by:

where \(r_{i,j}\) is the partial residuals across as found by:

#### Naive Updates¶

Improved efficiency can be found by updated via:

where \(r_i\) is the current model residual for all samples, \(n\).

#### Covariance Updates¶

When the number of samples is much greater than the number of features (\(n \gg p\)) further efficiency boosts can be gained by replacing the first term of the * Naive update* above as:

#### Warm Starts¶

It has been shown that fitting a sequence of models using the solution of one as the starting coefficient values of the next can be faster than a single fit for some small \(\lambda\) values. This sequence should begin at \(\lambda_{max}\), the smallest value of the tuning parameter for which all coefficient estimates are brought to zero, and end at \(\epsilon \cdot \lambda_{max}\) with around 100 values on a log scale where \(\epsilon\) is typically 0.001:

\(\lambda_{max}\) can be found by finding the minimum value that will bring the estimates for all model coefficients to zero. Thus any values greater than this value will result in total sparsity of the coefficient vector. This value can be found as:

When * warm starts* are utilized the Coordinate Descent algorithm is referred to as

*. [3][4][2][1][5]*

**Pathwise Coordinate Descent**### Implementation in Python Using NumPy¶

Warning

In practice it is recommended to use a cross-validation technique such as K-Fold cross-validation to choose the tuning parameter, \(\lambda\).

### Implementation in Python Using Scikit-Learn¶

## Sources¶

- 1
Regularization: ridge regression and the lasso. Nov 2006. URL: http://statweb.stanford.edu/~tibs/sta305files/Rudyregularization.pdf.

- 2
Anil Aswani. Ieor 165 – engineering statistics, quality control, and forecasting lecture notes 8. Jan 2021. URL: http://courses.ieor.berkeley.edu/ieor165/lecture_notes/ieor165_lec8.pdf.

- 3
Jerome Friedman, Trevor Hastie, and Rob Tibshirani. Regularization paths for generalized linear models via coordinate descent. Aug 2010. URL: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2929880/.

- 4
Trevor Hastie, Jerome Friedman, and Rob Tibshirani. Fast regularization paths via coordinate descent talk. 2009. URL: https://web.stanford.edu/~hastie/TALKS/glmnet.pdf.

- 5
Trevor Hastie, Jerome Friedman, and Robert Tisbshirani.

*The Elements of statistical learning: data mining, inference, and prediction*. Springer, 2017. URL: https://web.stanford.edu/~hastie/ElemStatLearn//printings/ESLII_print12_toc.pdf.

Contributions made by our wonderful GitHub Contributors: @wyattowalsh