Math calculator

Ridge Regression Calculator

Shrink to predict.

Shrink to predict

Thirty observations, eight predictors that all share a common factor, and only the first three matter. Least squares has almost nothing to work with: it returns 2.597 for a predictor whose true coefficient is 1.0, and −0.778 for one whose true coefficient is 0. Ridge pulls everything toward zero — 1.395, 0.676, 0.702 for the three real ones — and that deliberate understatement lowers the cross-validated error from 1.1678 to 0.9092, a 22.14% improvement, at 63.5% total shrinkage. The estimate is more biased and more accurate at the same time.

30 rows · 8 predictors · condition number 22.727 · largest variance inflation 33.06

Penalty 0.05 cuts cross-validated error by 22.14%, at 63.5% shrinkage

Every coefficient is pulled toward zero, which makes the estimate more biased than least squares by construction, and it predicts better anyway. That trade is worth making when the data is thin relative to the number of predictors and they move together — which is exactly what a condition number of 22.73 and a variance inflation of 33.1 describe.

Chosen penalty

0.05

cross-validated error 0.9092

Least squares error

1.1678

22.14% worse

Shrinkage applied

63.5%

of the coefficient norm

Largest variance inflation

33.06

severe collinearity

Every coefficient, pulled in

Least squares and ridge coefficients on the standardised scale, with the original-scale version
PredictorLeast squaresRidgePulled in byOn the original scale
x12.59741.39461.20281.07745
x20.81670.67580.14080.50480
x31.07400.70240.37160.54025
x4-0.10160.3647-0.26300.27685
x50.69950.64470.05470.50178
x6-0.45650.30960.14690.23050
x7-0.7782-0.25350.5247-0.20468
x8-0.0328-0.0412-0.0085-0.03136
Intercept0.03316

Ridge never sets a coefficient to exactly zero — the penalty is smooth at the origin, so there is no corner for a coefficient to catch on. Everything is kept and everything is reduced, which is a different thing from selection. Averaged over 200 simulated draws, true coefficients of 1.0 come back at about 0.68: that understatement is not a defect but the mechanism.

The whole penalty path

Cross-validated error and coefficient size at each penalty
PenaltyCross-validated errorIts standard errorCoefficient norm
0.000011.167480.122899.8765
0.00011.164940.122219.8291
0.00051.154140.119329.6256
0.0011.141620.115979.3868
0.0051.068530.098527.9248
0.011.014230.093336.7528
0.050.909220.129083.6056lowest error
0.10.910770.146012.6482
0.51.034370.189721.6918one standard error rule
11.210300.253581.4544

The coefficient norm falls monotonically as the penalty rises, which it must. The error does not: it falls, reaches a minimum, then climbs as the fit is shrunk past usefulness. The one-standard-error rule picks the largest penalty whose error is still within one standard error of the best — here 0.5 — on the argument that a simpler fit should win ties.

At a penalty of zero this is ordinary least squares exactly — the suite confirms the two agree to 0.0e+0 — so the path starts from the unpenalised fit rather than approximating it.

Ridge keeps every predictor. If the goal is to decide which ones matter, lasso sets coefficients to exactly zero — though which ones it picks is far less stable than it looks. The penalty itself is chosen by cross-validation, which is a noisier procedure than a single number suggests.

Bias shown directly Least squares beside it Full penalty path Collinearity measured A plenty-of-data preset

What this tool shows

On the first preset three predictors have a true coefficient of 1.0, and ridge returns 1.395, 0.676 and 0.702. Every estimate is wrong on purpose, and the cross-validated error falls 22.14%. Least squares, with thirty rows and eight collinear predictors, returns 2.597 for one of those same coefficients. Averaged over 200 draws, ridge brings true values of 1.0 back at about 0.68. That understatement is the mechanism, not a defect — and it is entirely a small-sample phenomenon: against a fresh test set ridge beat least squares by 19.83% at thirty rows, 2.35% at sixty, 0.28% at two hundred, and by −0.04% at four hundred.

  • A penalty path with cross-validated error and its standard error at every point
  • Least squares beside it, so the shrinkage is visible coefficient by coefficient
  • The condition number and variance inflation, which say whether ridge has anything to fix
  • The one-standard-error rule alongside the minimum-error choice
  • Coefficients on both the standardised and the original scale, with an intercept
  • A preset with plenty of data where ridge correctly does almost nothing
Bias shown directly Least squares beside it Full penalty path Collinearity measured

Ridge is biased by construction. That is what it is for.

Updated 13 September 2026 · Works in any browser, no installation

Ridge regression adds a penalty on the size of the coefficients, which pulls every estimate toward zero and makes all of them biased — and when predictors are correlated and data is scarce, that reduces total error. Least squares is unbiased, which sounds like the better property and is not the only one: an unbiased estimate with enormous variance is wrong in a different way every time you collect data. Ridge accepts being consistently a little low in exchange for being far less erratic.

At a glance

Formula shown
Ridge minimises ‖y − Xβ‖²/2n + λ‖β‖²/2, giving β = (XᵀX + nλI)⁻¹Xᵀy on standardised predictors. At λ = 0 it is ordinary least squares exactly. As λ rises every coefficient shrinks toward zero and none reaches it, because the squared penalty is smooth at the origin and offers no corner for a coefficient to stop at. The penalty is chosen by cross-validation over a path.
Scenario support
Many predictors relative to observations, predictors that move together (survey items, lagged variables, spectral channels, related financial ratios), any fit where least squares produces coefficients too large or with the wrong sign, and prediction problems where interpreting individual coefficients is not the goal.
Educational estimate
Planning support from the values you enter — not professional advice.

Wrong on purpose, and better for it

The first preset was generated with three predictors whose true coefficients are exactly 1.0 and five whose true coefficients are exactly 0, from thirty observations of eight predictors that all share a common factor.

Least squares has almost nothing to work with. It returns 2.597 for one of the coefficients that should be 1.0, 0.817 for another, and −0.778 for one that should be 0. These are not small errors; with collinear predictors and thirty rows, the fit is chasing noise and reporting it with a straight face.

Ridge returns 1.395, 0.676 and 0.702 for the three real coefficients. Also wrong — and wrong in a systematic direction, all pulled toward zero. Averaged over 200 simulated draws, true values of 1.0 come back at about 0.68, a consistent 32% understatement. That is the bias, it is real, and it does not go away with more draws.

The cross-validated error falls from 1.1678 to 0.9092. A 22.14% improvement, bought with 63.5% shrinkage of the coefficient norm. The estimator that is reliably a bit low beats the one that is unbiased on average and wildly variable in any particular sample.

This is what the bias-variance trade means in practice, and it is worth seeing as numbers rather than as a curve in a textbook. “Unbiased” is a statement about the average across datasets you will never collect. You have one dataset.

When it stops helping

The advantage is not a property of ridge; it is a property of the situation. Holding the design fixed at eight collinear predictors and varying only the sample size, each setting simulated forty times and scored against a fresh six-hundred-row test set:

At twenty-five rows ridge beat least squares by 19.83%, winning on 36 of 40 draws. At thirty, 14.39%. At forty, 6.06%. At sixty, 2.35%. At a hundred, 0.69%. At two hundred, 0.28%. At four hundred, −0.04%— it lost, narrowly.

The second preset is that case made concrete: the same eight predictors with 220 observations. Least squares now returns 0.891, 1.009 and 0.975 for the three true coefficients of 1.0, which is close enough that there is little left to fix. Ridge improves the error by 0.46% and applies only 11.6% shrinkage.

That is the reassuring part of the method. Cross-validation chooses the penalty, so when shrinkage is unnecessary it chooses a small one and the fit converges on least squares. Ridge does not need to be justified in advance; it needs a path and an honest error estimate.

Why standardising is part of the method

The penalty is on the sum of squared coefficients, so it treats a coefficient of 3 as three times more costly than one of 1. But a coefficient depends on the units of its predictor: measure a distance in metres instead of kilometres and its coefficient falls by a factor of a thousand.

Unstandardised, ridge would therefore penalise predictors according to the units someone happened to record them in, which is not a statistical decision anyone intends to make. Every predictor here is centred and scaled to unit standard deviation before fitting, and the coefficients are converted back afterwards, with an intercept, so both scales are available.

The intercept is never penalised. Shrinking it toward zero would mean shrinking the predicted outcome toward zero, which has no motivation at all — it would make the fit depend on whether the outcome happens to be measured in degrees Celsius or Kelvin.

Choosing the penalty

The path table gives cross-validated error at every penalty, with its standard error beside it. The minimum is marked, and so is the one-standard-error choice: the largest penalty whose error is still within one standard error of the best.

That second rule exists because the minimum is not as well determined as it looks. The error curve is usually flat near its bottom, so several penalties are statistically indistinguishable and the one that happens to win is partly an accident of the fold split. When choices tie, the more shrunk fit is the more defensible one.

How unstable that choice is can be measured directly, and the cross-validation page does it: re-drawing the folds on the same data moves the chosen penalty across a tenfold range while the error it achieves varies by about two per cent. Reporting a single optimal penalty as though it were determined by the data overstates what happened.

Ridge against the alternatives

Ridge keeps every predictor. It cannot do otherwise: the squared penalty is smooth at the origin, so there is no corner for a coefficient to catch on, and the path table confirms the count of non-zero coefficients never falls. If the question is which predictors matter, ridge does not answer it.

Lasso does set coefficients to exactly zero, and pays for it: the set it selects is far less reproducible than the coefficients themselves. Elastic net sits between them on a dial.

Where the problem is collinearity specifically rather than too many predictors, component regression attacks it by replacing the predictors with a few directions — which has a failure mode of its own, since the directions carrying the most variance need not be the ones related to the outcome. And the plain diagnostic for collinearity is the variance inflation factor, reported here alongside the condition number.

Reporting it

Report the penalty, how it was chosen, and the cross-validated error at that penalty and at zero. The gap between those two is the entire case for having regularised, and without it a reader cannot tell whether the penalty did anything.

Do not report ridge coefficients as effect estimates. They are shrunk on purpose, by an amount that depends on the penalty and on how collinear the predictors are, so a ridge coefficient is smaller than the effect it estimates and there is no standard error that repairs that. Confidence intervals for penalised coefficients are a live research problem rather than a routine output.

State the condition number or the largest variance inflation factor. They are what justify reaching for a penalised method in the first place, and on data where both are near one the honest report is that least squares was adequate.

Sources and methodology

References for the estimator and its computation.

Method. Coefficients are obtained in closed form from the penalised normal equations on standardised predictors, with the penalty scaled by n so that a given value means the same thing here as on the lasso and elastic net pages. The suite confirms three exact identities: ridge at a penalty of zero equals ordinary least squares to 0.0e+0; elastic net with no lasso share reproduces this fit to within 1e-8 at four different penalties, which is a coordinate-descent routine agreeing with a matrix inverse; and rescaling a predictor leaves the standardised coefficients unchanged while rescaling the original-scale one by exactly the same factor. It further checks that the coefficient norm falls monotonically along the path and that no coefficient ever reaches zero. That engine is verified on every change against 395 assertions. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Lasso RegressionFit a lasso across a penalty path with cross-validation, and see how often each selected predictor survives when the rows are resampled.
Elastic NetFit an elastic net across the mixing dial from pure lasso to pure ridge, with selection stability and cross-validated error computed at each end.
Cross-ValidationRun k-fold cross-validation over a penalty path and repeat it across twelve fold assignments, so the variability of the chosen tuning parameter is visible.
Principal Component RegressionRegress on principal components with each component's variance share printed beside its correlation with the outcome, and the error at every component count.
VIFVariance inflation factors with Belsley-Kuh-Welsch condition indices and variance-decomposition proportions, so a near-dependency is named rather than only detected.
Multiple RegressionFits several predictors with a VIF on every term, and names the configuration people misread: a model significant at p = 0.0103 where neither predictor reaches 0.05, at a VIF of only 7.11.

More in Math, or browse all calculators.

Educational use disclaimer

An educational tool. Ridge coefficients are biased toward zero by design and should not be reported as effect estimates; valid confidence intervals for penalised coefficients require methods beyond the scope of this page. The advantage over least squares depends on sample size and collinearity and can be negligible or slightly negative when data is plentiful.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (5 updates)

Published 13 September 2026

  1. Published a ridge penalty path with cross-validated error and its standard error at every point.
  2. Showed the bias directly: every coefficient pulled toward zero against the least squares fit beside it.
  3. Measured the advantage against sample size, from 19.83% at twenty-five rows to nothing at four hundred.
  4. Reported the condition number and variance inflation, which say whether a penalty has anything to fix.
  5. Shipped a plentiful-data preset where cross-validation correctly declines to shrink.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.