Skip to content
StackDecode
AI & ML Atlas
Machine LearningalgorithmInteractive simulation

Elastic Net Regression

Mixes the L1 and L2 penalties to get sparsity and stability.

The idea

It adds both λ₁Σ|w| and λ₂Σw². The L1 part drops useless features; the L2 part keeps groups of correlated features together instead of choosing one at random. A mixing ratio sets the balance between them.

minimise Σ(y − ŷ)² + λ(α·Σ|w| + (1−α)/2·Σ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 the overall strength and the L1/L2 mix.
  3. 3Minimise error + L1 + L2 penalties.
  4. 4Tune both settings with cross-validation.

Where it is used

High-dimensional data with correlated predictors.

Watch out for

Two hyper-parameters to tune instead of one.

Related