Ridge & Lasso
A flexible model can fit accidental details in the training data. Penalising large coefficients gives us a way to discourage that behaviour, with ridge and lasso making different kinds of adjustment.
17 sections · 15 questions · 4 coding challenges
The arrow keys move between sections too.
Why Can a Small Change in the Data Produce Huge Coefficients?
BOTIE
Hoerl and Kennard examined this instability in their 1970 ridge regression paper. They accepted some bias in exchange for more stable estimates by penalising large coefficients. Tibshirani's 1996 lasso paper combined shrinkage with variable selection: its different penalty could set some coefficients exactly to zero.
Both methods make the model pay for coefficient size as well as prediction error. Ridge discourages large coefficients smoothly. Lasso can remove a contribution entirely. We are choosing a compromise, so the penalty strength needs evaluation on data beyond the fitting sample. Neither penalty can tell us, by itself, which variables are causes.
A Better Fit Can Make a Worse Prediction
A flexible model can follow accidental noise and rely on large contributions that nearly cancel. Its training predictions may look good while small data changes produce a very different rule.
Regularization adds a preference for restrained coefficients. We will see that tradeoff before writing the penalty formulas.
A close training fit is only one goal
An elaborate rule has many ways to follow a small sample. Training error rewards those details whether or not they repeat in new data. Stability asks a different question.
Fit this sample
- Small training errors
Remain stable
- Limited unnecessary sensitivity
A penalty is a preference to evaluate
The squared-coefficient and absolute-value penalties explain the different behaviour of ridge and lasso. Their formulas now have a visible purpose.
Use suitable feature scales and validation data to choose the strength. The full experiments show actual coefficient paths and prediction errors.
Explore the full example
Increase the penalty and compare the curve and its coefficients. Notice what the model gives up in training fit as the coefficients shrink.
The bars are the nine coefficients on a shared scale. Indigo is positive, amber is negative, grey is switched off.
…
Part 1. Why Restraining a Model Can Help
1. Revisit the overfit polynomial
The box above is the polynomial page’s problem, the same noisy throw fitted at degree 9, far more flexibility than a ball deserves. Set the penalty slider to its lowest and the fit answers only to the data. It scores 0.997 on the fifteen readings, and on the polynomial page the same curve scored −5479 on four readings held back from it. The training score and the held-out score are not measuring the same thing, and the whole of this page follows from the gap between them.
Look at the bars under the curve rather than the curve. Each is one of the nine coefficients. They are what the fit actually chose, and everything the curve does between the readings is built out of them.
2. Large contributions that cancel
Bars alone do not show how the terms interact, so pick one moment in time and take the prediction there apart. Each term contributes its coefficient times its column, positives stack upward and negatives stack downward, and the prediction is where the stack ends.
| term | intercept | sum |
|---|---|---|
| metres at t = 2.00 | … | … |
At t = 2, with no penalty
The positive terms add up to 77,446 metres. The negative terms add up to −77,438. The intercept is 12.76, and the prediction is 20.39, a sensible height for a ball two seconds into a throw, assembled out of pieces the size of mountains that cancel to within eight metres of each other.
At a penalty of 1 the same prediction is 17.69, built from positives totalling 5.2 and negatives totalling −0.2.
A moderate prediction produced by large opposing pieces is sensitive to the smallest change in any of them. Nudge the t⁶ coefficient by a hundredth of a percent and the prediction moves by more than four metres. That sensitivity is the problem regularisation is for, and it is worth seeing before any penalty is mentioned.
3. Sensitivity to the training sample
Coefficient size matters because of what it does when the data changes. Below, the same degree-9 model is fitted three times, on the noisy throw, on the same readings with one of them moved a metre and a half, and on a fresh set of readings of the same throw with its own noise.
| Sample | Training R² | Largest coefficient | Coefficient on t, t², t³ |
|---|---|---|---|
| Sample A | … | … | … |
| Sample B, one reading moved | … | … | … |
| Sample C, fresh noise | … | … | … |
| Sample | Training R² | Largest coefficient, no penalty | Largest coefficient, λ = 1 |
|---|---|---|---|
| A, the noisy throw | 0.997 | 85,263 | 7.64 |
| B, one reading moved | 0.993 | 76,525 | 7.80 |
| C, fresh noise | 0.999 | 28,206 | 7.81 |
Three excellent training scores, three sets of coefficients that agree on nothing, and one penalty that brings them within two percent of each other.
Small change in the data, large change in the coefficients, large change in the curve between the readings. That is what an unstable model is, and it is a stronger case for restraint than the curve looking implausible, because it says the fit will not survive contact with the next sample.
Part 2. Two Goals in One Objective
4. Fit versus restraint
There are two things to want from a fit. It should match the observed data, and it should not depend on extreme coefficients to do it. Section 3 offers exactly that choice. Sample A with no penalty scores 0.997 with a largest coefficient of 85,263. At λ = 1 it scores 0.846 with a largest coefficient of 7.64.
So the question is not whether the second model fits worse. It does. The question is how much training error you would accept in exchange for a model that does not fall apart when one reading moves, and that is a trade rather than a correction. Regularisation makes the trade deliberately.
5. The regularised objective
Write the trade down as one number to minimise, made of two parts.
total objective = data error + coefficient cost
total objective = RSS + λ · penaltyRSS is the residual sum of squares from every regression page so far, and asks how well the model fits the readings. The penalty asks how costly the coefficients are. λ sets the relative price of the two. Below, the objective is drawn at every λ on the path in its two halves, grey for RSS and colour for λ times the penalty, and the fit at each λ is the set of coefficients that made the whole bar shortest.
The fitted curve at this λ
Regularization minimizes a combined objective. At penalty one, this fit accepts a larger residual sum of squares in exchange for smaller coefficients.
combined objective ≈ residual cost + penalty cost
≈ 101 + 79 = 180The unpenalized fit’s residual cost was only about 1.7, but its coefficient penalty would make its combined objective larger. Compare complete objectives when judging which solution the regularized fit should choose.
6. What λ controls
| λ | What the fit cares about | What happens |
|---|---|---|
| 0 | training error only | ordinary least squares comes back exactly |
| moderate | error and coefficient size | coefficients shrink, RSS rises a little |
| very large | coefficient size dominates | the penalised coefficients head to zero and the curve toward the intercept alone |
λ does not set a coefficient. It changes the trade that decides them all, which is why sliding it moves every bar in the box at the top of the page at once. The path above is drawn on a log scale because the useful values run from a thousandth to ten, and a linear slider would spend most of its length past the point where anything interesting happens.
Keep in mind
A value of λ means nothing on its own. It is a price, and the same number buys a different amount of restraint depending on the scale of the features, the scale of the target, whether the error is summed or averaged, and any constant the objective carries. The λ that works here is not the λ that works on other data, or on this data written as mean squared error rather than RSS. It only ever means something relative to the objective it sits inside.
Part 3. Why Features Must Be Put on Comparable Scales
7. Why feature scale matters
The regression page’s slope is 0.8 kilograms per centimetre. Expressing height in metres makes the slope eighty kilograms per metre. The height contribution to the prediction stays the same.
in centimetres: 0.8 × 170 = 136
in metres: 80 × 1.70 = 136
coefficient ratio = 80 / 0.8 = 100
squared-penalty ratio = 100² = 10,000The predictions are unchanged, but the penalty is not. This is why the units of a feature matter to regularization.
The same five people, twice
| Height in | Ordinary slope | β² | Ridge slope at λ = 50 |
|---|---|---|---|
| centimetres | 0.8 kg per cm | 0.64 | 0.667 kg per cm |
| metres | 80 kg per m | 6400 | 0.040 kg per m |
0.040 kg per metre is 0.0004 kg per centimetre. The same data, the same λ, and one fit is shrunk by a sixth while the other is all but switched off.
A large coefficient can mean a feature matters a great deal, or it can mean the feature was measured in small units. Penalising raw coefficients charges for units rather than for complexity, and the choice of units ends up choosing the model.
8. Standardizing before regularisation
The repair is the statistics primer’s z-score, applied to every feature column before the fit.
zⱼ = (xⱼ − x̄ⱼ) / sⱼSubtracting the mean centres the column. Dividing by its standard deviation puts every column on a common spread, so a coefficient of 2 means the same thing whichever column it sits on, and the penalty can compare them. Every fit on this page does this. The bars in the box at the top are coefficients on standardized columns, which is why t⁹, whose raw values reach 262,144, can be drawn beside t.
Centring also settles the intercept. On centred features the intercept is the prediction at the average of every input, which for the throw is the mean height, 12.76 metres. That number sets the overall level of the predictions rather than how they respond to any feature, and penalising it would pull every prediction toward zero rather than toward the data. So the coefficients are charged and the intercept is not, on both of this page’s models.
Keep in mind
That is a convention rather than a law, and libraries differ on it. And the means and standard deviations must be learned from the training rows only, then applied unchanged to any held-out rows. Recomputing them on the held-out data lets the judge see the answers, which is the leak the pipelines page measures.
Check yourself
Questions on Parts 1 to 3
Question 1 of 5
At no penalty the positive terms at one moment total 77,446 metres and the negative terms −77,438. What does the lesson take from that?
Part 4. Ridge Regression
9. Ridge's squared penalty
Ridge charges the sum of the squared coefficients.
RSS + λ · Σ βⱼ²Before combining it with anything, look at what β² costs for one coefficient. Zero costs nothing, 1 costs 1, 2 costs 4, 4 costs 16. Moving away from zero becomes increasingly expensive, a positive and a negative coefficient of the same size cost the same, and the curve is smooth everywhere, including at zero.
Ridge, β²
Lasso, |β|
The slope readout is the part to notice now and use later. The slope of β² is 2β, which at zero is zero. Near zero, ridge barely pushes at all, and that is why its coefficients approach zero without arriving. The other panel is Part 5.
10. Ridge shrinkage by hand
For one feature the ridge answer can be worked out completely, and the conditions are worth stating because the formula depends on them. One feature. Feature and target both centred, so the intercept is handled separately and drops out. And the objective written as RSS, not a mean and not halved.
Σ (yᵢ − βxᵢ)² + λβ²Ordinary least squares on centred data gives the slope as a ratio of two sums, and ridge changes exactly one thing about it.
β = Σxᵢyᵢ / Σxᵢ² ordinary
β = Σxᵢyᵢ / (Σxᵢ² + λ) ridgeFor the five-person dataset, the centred cross-product is 200 and the centred sum of height squares is 250.
ridge slope = 200 / (250 + λ)Increasing the penalty increases the denominator and shrinks this slope toward zero.
Worked example
| λ | denominator | ridge slope |
|---|---|---|
| 0 | 250 | 200 / 250 = 0.8 |
| 50 | 300 | 200 / 300 = 0.667 |
| 250 | 500 | 200 / 500 = 0.4 |
| 1000 | 1250 | 200 / 1250 = 0.16 |
The λ of zero row is the regression page's fit, recovered exactly. The numerator never changes; the denominator grows without limit, so the slope drains toward zero and never reaches it.
The whole objective is drawn below over the slope, RSS as a parabola with its floor at 0.8, the penalty as a second parabola with its floor at zero, and their sum. Slide λ and the sum’s lowest point slides toward zero.
Ridge, RSS + λβ²
Grey dashes are RSS alone, coloured dashes the penalty, solid their sum. The dot is the lowest point of the sum.
Lasso, RSS + λ|β|
Grey dashes are RSS alone, coloured dashes the penalty, solid their sum. The dot is the lowest point of the sum.
The indigo curve on the shrinkage path below is that formula fitted at every penalty from 0 to 500. The amber curve is Part 5.
Ridge divides the slope by a factor that grows with the penalty so it only ever approaches zero, while lasso subtracts a fixed amount each step and so actually arrives.
11. Ridge with correlated features
With several features the coefficients are fitted together, and the one-feature picture needs care to generalise. What ridge does is discourage large overall coefficient magnitude. It generally keeps every feature with a nonzero coefficient, and it steadies the fit when features are correlated, which is the case Hoerl built it for. What it does not do is shrink every coefficient at the same rate, or shrink the noisiest first, or hold an opinion about which features deserve a say.
The path below is every one of the nine polynomial coefficients against log λ, and they cross each other, change sign and shrink at nine different speeds.
The right-hand panel is the point of the exercise. The training score only ever falls as λ rises, since every penalty is a constraint the free fit did not have. The held-out score, on four readings the fit never saw, climbs from ruin at no penalty to 0.993 near λ = 0.0001 and only then begins to fall. Restraint buys prediction, up to a point, and Part 7 is about finding the point.
Why correlated features are steadied is a geometric fact and deserves its own picture. Below, two columns track each other, the second close to twice the first, and the residual sum of squares is drawn over every pair of coefficients.
…
Reading the valley
The RSS forms a long shallow valley, because raising the first coefficient and lowering the second by half as much barely changes any prediction. Least squares sits at the valley’s lowest point, (4.61, 0.12). Tick “jostle the sample” and the target is disturbed by a fraction of its spread, and the least-squares point slides along the floor to (5.99, −0.57), a move of one and a half in the first coefficient from a change that barely dented the fit.
Ridge at λ = 1 sits at (1.21, 1.78), and after the same jostle at (1.31, 1.73). It moved a tenth. The circle is the set of coefficient pairs with the same squared penalty as the solution, and the solution is where an RSS contour first touches that circle. A long valley meets a circle at one well-defined place; it meets nothing at all along its own floor.
Notice also where ridge went. Not toward the origin along the line from the least-squares point, but across, to a pair where both coefficients carry some of the effect. Two large opposing coefficients cost a great deal in β², and two moderate shared ones cost less while predicting nearly the same, so ridge picks a smaller and steadier pair from among the many that fit similarly. That is the whole of what “spreading credit across correlated inputs” means, and it is a consequence of the circle rather than a belief about features.
Part 5. Lasso Regression
12. Lasso's absolute-value penalty
Lasso charges the sum of the absolute values instead.
RSS + λ · Σ |βⱼ|For one coefficient the cost is 0, 1, 2, 4 for β of 0, 1, 2, 4, a straight line either side of zero. Go back to section 9’s widget and drag β across both panels. Ridge is a bowl, smooth at the bottom. Lasso is a V with a corner at zero, and its slope is +1 on one side and −1 on the other, the same size everywhere and undefined exactly at the corner.
So lasso pulls toward zero with constant force, however small the coefficient already is, where ridge’s pull fades as the coefficient does. The corner is what makes the difference in the next two sections.
13. Lasso shrinkage by hand
Same conditions as section 10, one centred feature, RSS without a half. Write the two sums as S for short.
Sₓᵧ = Σxᵢyᵢ = 200 Sₓₓ = Σxᵢ² = 250For a positive slope the lasso answer subtracts from the numerator rather than adding to the denominator.
β = (Sₓᵧ − λ/2) / Sₓₓ while λ/2 < Sₓᵧ
β = 0 once λ/2 ≥ SₓᵧIn this one-feature example, lasso subtracts half the penalty from the positive data term before dividing by 250. Once the subtraction exhausts that term, the solution is zero.
positive slope = max(0, 200 − λ/2) / 250
zero threshold: λ/2 = 200
λ = 400This exact zero is the feature of lasso that the ridge solution does not share in this example.
The flat stretch is every ordinary slope the penalty sends to exactly zero. The dot is the worked slope of 0.8.
The half comes from the objective being written as RSS with no factor in front, so that the derivative of the squared term carries a 2 the penalty term does not. Write the objective with a half, or as a mean, and the threshold moves. The mechanism does not.
The amber path in section 10’s shrinkage chart is this formula fitted at every λ, and it walks straight into zero at 400 and stays. Ridge’s indigo path passes 0.31 there and keeps gliding.
14. Why lasso reaches zero
Return to section 10’s two panels, which draw the same RSS parabola under both penalties, and slide λ upward. The ridge minimum moves toward zero continuously and sits just beside it however far λ goes. The lasso minimum arrives at zero at λ = 400 and stays there for every λ after.
›Why the corner holds the minimum
At any coefficient other than zero the objective has a slope, and the minimum is where that slope is zero. The slope of RSS at β is −2(Sₓᵧ − Sₓₓβ), and the slope of the ridge penalty is 2λβ, which vanishes at zero, so at β = 0 the only pull is the data’s, and the minimum cannot sit there unless the data has no pull at all.
The lasso penalty has no single slope at zero. Just to the right its slope is +λ, just to the left it is −λ, and every value between −λ and +λ counts as a slope at the corner. Zero is the minimum whenever the data’s pull, 2Sₓᵧ, lies inside that range, which is whenever λ ≥ 2Sₓᵧ, or λ/2 ≥ Sₓᵧ. A whole range of data pulls is balanced at the corner, and that range is what the flat stretch in section 13’s map draws.
Lasso can remove a coefficient because a penalty with a corner can overpower a weak data contribution at a finite λ. A penalty that is smooth at zero never can.
15. Sparse models and feature selection
On the nine polynomial terms the lasso paths below do what the one-feature arithmetic predicts. Coefficients arrive at the zero line and stay, the count of active terms falls, and the fitted curve keeps its shape on fewer and fewer terms.
Two things on that chart are easy to over-read. The active count is not monotone. It falls from 9 to 6 by λ = 0.056, to 4 by 0.178 and to 2 by 3.2, then rises to 3 at 5.6 before falling back to 2 at 10, because a term that was switched off came back when a correlated neighbour was shrunk and its share of the work needed picking up. And the first term to reach zero is not the least important term in any objective sense. It is the term whose contribution the others could most cheaply absorb at that λ, on this sample.
A model that ends with most coefficients at exactly zero is smaller and easier to inspect, and in a setting with hundreds of candidate features that can be worth more than the predictions. It is a sparse predictive representation, and it is not a list of which features matter.
Keep in mind
A zero coefficient means the fitted model is not currently using that feature. It does not prove the feature has no relationship with the target. With correlated inputs lasso may keep one and drop another that carries nearly the same information, and a different sample can change which. In section 11’s valley, switch to lasso at λ = 0.18.
On the original sample it keeps both columns, at (4.15, 0.35). Jostle the sample and it drops the second entirely, (4.84, 0). Raise λ past 3 and on both samples it drops the first instead and keeps the second at 2.38, since one unit of the second column does the work of two units of the first at half the absolute cost.
Polynomial powers are strongly correlated with each other over a short interval, which makes them a good demonstration of instability and a misleading demonstration of tidy feature selection.
Check yourself
Questions on Parts 4 and 5
Question 1 of 5
With a centred cross-product of 200 and a centred sum of squares of 250, what does the one-feature ridge slope do as λ grows?
Part 6. Ridge and Lasso Compared
16. Ridge and lasso side by side
Everything above used the same data, the same standardization, the same degree-9 columns, the same held-out split and the same λ scale, so the two can be set beside each other fairly.
| Ridge | Lasso | |
|---|---|---|
| penalty | squared magnitude, Σβ² | absolute magnitude, Σ|β| |
| one-feature solution | divide the pull by Sₓₓ + λ | subtract λ/2 from the pull, then divide |
| typical coefficient pattern | many smaller values, rarely an exact zero | some exact zeros |
| correlated features | often shares the weight between them | may keep one and drop another |
| path as λ grows | smooth | kinks where a coefficient reaches zero |
| closed form with many features | yes, section 21 | no, section 22 |
| main use | stability and shrinkage | shrinkage and sparsity |
Neither is the better method. Ridge is the one to reach for when many features each carry a little signal and the problem is instability. Lasso is the one to reach for when the model has to be small enough to read, or when most of the features are believed to be irrelevant. Both are available at once, in the elastic net, which is a share of each penalty.
17. The geometry of their penalties
The clearest account of why one produces zeros and the other does not is section 11’s valley, with the toggle set to lasso. For two coefficients the RSS contours are ellipses. Ridge’s penalty is a circle, and the solution is where the expanding circle first touches the best available contour. Lasso’s penalty is a diamond, |β₁| + |β₂| constant, and its corners lie on the axes, exactly where one coefficient is zero.
An ellipse meeting a circle touches it at a point with no special relationship to the axes, so both coefficients come out nonzero. An ellipse meeting a diamond very often touches it at a corner first, because corners stick out, and a corner is a solution with one coefficient at exactly zero. Slide the λ control with lasso selected and watch the green dot ride the diamond’s edge until it snaps onto the vertical axis at λ ≈ 3, where the first coefficient is zero from then on.
Lasso produces zeros because the shape of its penalty has corners on the coefficient axes, and ridge does not because a circle has none.
Part 7. Choosing the Penalty
18. Training error versus validation error
The dashboard below is every instrument on one λ. Pick a penalty and read the objective, the coefficients, the fitted curve and the two scores together.
The fitted curve at this λ
The pattern to see is in the scores panel. Training R² only falls as λ grows. Held-out R² rises first, because the unpenalised fit was memorising the eleven training readings, and then falls, because too much restraint stops the curve from following the arc at all. Under ridge the turn is near λ = 0.0001 on this split, and under lasso near 0.1. Those numbers belong to this data, this standardization and this split, and to nothing else.
The penalty is chosen by performance on data that did not determine the coefficients. Nothing on the training side of the chart can choose it, since that side always prefers λ = 0.
19. Choosing λ
The old rule on this page said the right penalty is past the wiggle and short of the flatline, and the box at the top still shows what that means. Keep it as a picture of the trade and not as a procedure. A curve that looks moderate is not evidence that it will predict well, and two λ values that produce curves you could not tell apart by eye can differ by a tenth in held-out score.
The procedure is the one section 18 previews. Fit several candidate values of λ on the training rows. Score each on held-out rows, or better, let every row take a turn as the judge, which is cross-validation. Choose by that score, and where it matters, confirm the choice once on data that took no part in choosing it. The held-out evaluation and grid search pages do this properly, including the part where the winning score flatters itself.
20. Degree selection versus regularisation
Both reduce overfitting and they make different choices. Choosing a lower degree removes whole columns from the model. Ridge keeps every column and shrinks its coefficient. Lasso keeps the columns and may zero some, and with raw polynomial powers it can keep t⁵ while dropping t⁴, so what survives is not a tidy polynomial of some lower degree.
Held-out R² over degree and λ, ridge, on the same split
| Degree | λ ≈ 0 | λ = 0.01 | λ = 1 | λ = 10 |
|---|---|---|---|---|
| 2 | 0.989 | 0.996 | −1.373 | −1.993 |
| 5 | 0.988 | 0.966 | −0.272 | −1.642 |
| 9 | 0.929 | 0.936 | −0.317 | −1.405 |
Flexibility has two controls, and validation can choose both. The best cell here is degree 2 with a small penalty, and degree 9 with the right penalty is close behind.
Two things in that table are worth a look. Degree 2 is already the right shape for a ball, and a small penalty still helped it, from 0.989 to 0.996. And λ = 1 is a heavy penalty on eleven standardized rows whatever the degree, which is section 6’s caution in numbers.
Part 8. Formal Derivation
21. Deriving ridge
In the matrix language of the polynomial page, the ridge objective and its solution follow in four lines.
| Expression | What changed |
|---|---|
| J(β) = ‖y − Xβ‖² + λ‖β‖² | RSS as a squared length, plus λ times the squared length of β |
| ∇J = −2Xᵀ(y − Xβ) + 2λβ | the polynomial page's gradient, plus the penalty's own derivative |
| Xᵀ(y − Xβ) = λβ | set the gradient to zero and divide by −2 |
| (XᵀX + λI) β = Xᵀy | collect β, the normal equations with λ down the diagonal |
With one centred feature XᵀX is the single number Σx², and the last line is section 10’s formula. With the intercept in play it is either kept out of β and fitted separately on centred data, as this page does, or the identity matrix gets a zero in the intercept’s position so that it alone goes uncharged. And as on the polynomial page, the system is solved directly rather than by forming an inverse.
›Why λI steadies the solution
XᵀX for the standardized degree-9 columns on the fifteen readings has eigenvalues running from 0 up to 125.7. Two of them are zero to machine precision and the next is one millionth, so the ratio of largest to smallest is about 7.6 trillion, and solving the plain normal equations means dividing by numbers that are effectively noise. That is where the coefficients of 85,263 come from.
Adding λI adds λ to every eigenvalue and changes nothing else about the matrix. At λ = 1 the smallest becomes 1 and the ratio falls to 126.7. The directions the data could not pin down are pinned to zero instead of to noise, and the directions it could pin down are barely touched.
22. Why lasso requires a different solver
J(β) = ‖y − Xβ‖² + λ‖β‖₁The same first step fails on the second term. |β| has no ordinary derivative at zero, so there is no gradient to set to zero and no linear system to solve, and lasso has no normal-equations solution with many features. It does have one with a single standardized feature, which is section 13, and in a few special designs, but nothing that plays the role of (XᵀX + λI)⁻¹.
What it has instead is the corner. At zero the absolute value admits every slope between −λ and +λ, a subgradient rather than a gradient, and zero is optimal whenever the data’s pull on that coefficient lies inside the range. The solver used here is coordinate descent. It sweeps the coefficients one at a time, and for each it holds the others fixed, which reduces the problem to section 13’s one-feature case on the current residual, applies the soft threshold, and moves on.
Repeated until nothing moves, that arrives at the lasso solution, one soft threshold at a time.
Part 9. Boundaries and Forward Connections
23. What regularisation does and does not tell us
After standardization and shrinkage a coefficient is not the number it was on the earlier pages. It is biased toward zero on purpose. Its size depends on the preprocessing and on λ, and it was chosen partly for the stability of the predictions rather than to describe the feature. A ridge coefficient of 0.3 on standardized t⁴ is a statement about what this fit decided at this λ, and not a measurement of how height depends on the fourth power of time.
In a model
Regularisation helps with the problems this page showed, excessive variance, correlated features, unstable coefficients and a model more flexible than its data can support. It does not repair a missing feature, a biased sample, a wrongly recorded target, data whose distribution has shifted since it was collected, a leak between the training rows and the held-out rows, or a model of the wrong form altogether. A penalised fit on the wrong columns is a stable fit on the wrong columns.
Those belong to evaluation and to data preparation, and the honest position for this page is that a penalty is one control among several, chosen by the same held-out score everything else is.
Check yourself
Questions on Parts 6 to 9
Question 1 of 5
Why does lasso produce zeros where ridge does not?
Try it with Botie
Build with Botie
Write and run Python