RegressionSample
Ridge & lasso regression
A flexible polynomial kept in check by a penalty on large coefficients.
Synthetic data, generated and trained in your browser.
Try this
- 01Start at the smallest λ: the coefficient bars hit their caps and the curve wiggles.
- 02Switch to lasso and raise λ: watch coefficients drop to zero one by one.
- 03Push λ to 1: both penalties flatten the curve towards the mean.
How it works
- 1Start from a degree-10 polynomial that would normally overfit.
- 2Add a penalty to the loss: the sum of squared coefficients (ridge) or of their absolute values (lasso).
- 3λ sets the trade-off between fitting the data and keeping coefficients small.
- 4Lasso can set coefficients exactly to zero, selecting features; ridge only shrinks them.
What the controls teach
- Penalty
- Ridge shrinks every coefficient smoothly; lasso pushes the least useful ones to exactly zero.
- Regularization λ
- Penalty strength. Near zero it overfits like plain polynomial regression; large values flatten the curve.
Use it when
- Many correlated or noisy features
- You want a simpler model (lasso)
Avoid it when
- Features on different scales without standardising them first