Skip to content
StackDecode
AI & ML Atlas
Machine LearningalgorithmInteractive simulation

Lasso Regression

Linear regression with an L1 penalty that can set weights exactly to zero.

The idea

The L1 penalty λ·Σ|w| has a corner at zero, so as λ increases some weights are pushed exactly to zero and drop out of the model. Lasso therefore does feature selection and regression in one step, giving sparse, easy-to-read models.

minimise Σ(y − ŷ)² + λ·Σ|wⱼ|

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

x1x2x3x4x5x6
  • positive weight
  • negative weight
  • true weight (dashed)

With no penalty the model fits the noise freely: even useless features get a small weight.

penalty:
0
zero weights:
0
1/15

Bars are the learned weights; dashed lines are the weights that generated the data. Features 3, 4 and 6 are pure noise.

Step by step

  1. 1Standardise the features.
  2. 2Choose λ.
  3. 3Minimise squared error + λ·Σ|w| (coordinate descent is common).
  4. 4Keep the features with non-zero weights.

Where it is used

Genomics and text where there are far more features than samples.

Watch out for

With correlated features it tends to pick one arbitrarily.

Related