Give a model a budget for how big its weights may be. See why Ridge shrinks them, why Lasso deletes them, and how Elastic Net blends both.
A model with many or large weights can fit noise. Regularisation changes the goal from “minimise the error” to “minimise the error plus λ times the size of the weights”. A bigger λ means a tighter budget. The only difference between the methods is how “size” is measured, and that decides the budget’s shape.
Round budget. Shrinks every weight smoothly, almost never to exactly zero.
Diamond budget with corners on the axes. Can set weights to exactly zero.
A blend: some zeros like Lasso, but steadier with correlated features like Ridge.
Convention used on this page. λ is the overall penalty strength and α ∈ [0, 1] is the share given to L1: α = 1 is pure Lasso, α = 0 is pure Ridge. The penalty is always λ[αΣ|w| + (1−α)Σw²/2]. In the top lab the loss is ½(w−w*)ᵀH(w−w*) with H = [[1, link],[link, 1]], which is exactly what the ellipses show. In the 10-feature demo the loss is (1/2n)Σ(y−ŷ)² on standardised features. That matches scikit-learn’s ElasticNet/Lasso (there, alpha = our λ and l1_ratio = our α). scikit-learn’s Ridge uses a different scaling (no 1/2n), so its alpha equals n·λ here. The “Train MSE” tile is Σ(y−ŷ)²/n, which is twice the loss term.
The best penalised solution is where the error ellipses first touch the budget shape. A circle is smooth, so the touch point can be anywhere. A diamond has sharp corners on the axes, and ellipses very often touch a corner, which means one weight is exactly zero. Switch to Lasso above and drag the target near an axis to see it.
The “soft threshold” is the heart of Lasso: if the pull toward a weight is smaller than λα, the weight is set to exactly 0. Otherwise it is shrunk by λα and divided by 1 + λ(1−α).
Here the model sees 10 features and 40 examples. Five features truly drive the answer; five are pure noise. x₁ and x₂ are strongly correlated (r ≈ 0.9), so they carry nearly the same signal. Slide λ to see who survives, and watch the test error (on 400 unseen examples) to find the sweet spot. Click the charts to set λ.
Same data, same λ, different budget shapes.
Lasso with a firm penalty: one weight lands exactly on the axis.
x₁ and x₂ carry the same signal. Lasso tends to keep one. Then switch to Elastic Net.
Push λ to the far right: every weight shrinks to nothing and the model underfits.