Skip to content

Ridge Regression Alpha Controls Regularization Strength

Ridge regression is least squares with a price on large coefficients, and the strength of that price is the parameter called alpha. It finds the coefficients that minimize the squared error plus α times the sum of the squared coefficients: ||y − Xβ||² + α||β||². The first term wants the line to fit the data. The second wants every coefficient close to zero. Alpha sets the exchange rate between the two.

James, Witten, Hastie, and Tibshirani write the same thing with λ in Equation 6.5, and scikit-learn's Ridge uses the name alpha for it. When alpha is 0, the penalty vanishes and you get ordinary least squares. As alpha grows, the penalty dominates and the coefficient estimates approach zero. Two details from the book matter in practice. The penalty is applied to the slopes, not to the intercept. And because a coefficient's size depends on the units of its feature, the authors recommend standardizing the predictors before applying ridge regression, so that the fit does not depend on the scale on which anything was measured.

Try it by hand. One feature, already centered: x = (−1, 0, 1), with y = (−2, 0.5, 2.5). Because x sums to zero, the intercept does not change the slope. Minimizing Σ(yᵢ − βxᵢ)² + αβ² gives β = Σxy / (Σx² + α). Here Σx² = 2 and Σxy = 2 + 0 + 2.5 = 4.5. At α = 0, β = 4.5/2 = 2.25, which is the least squares slope. At α = 1, β = 4.5/3 = 1.5. At α = 4, β = 4.5/6 = 0.75. Every step up in alpha pulls the slope toward zero, and the fit of the line to the three points gets looser in exchange. These three points are invented for the arithmetic.

Why would you accept a worse fit on purpose? The authors tie it to the bias-variance trade-off: as λ increases, the flexibility of the fit decreases, which lowers variance and raises bias. Sometimes that trade is worth it, and sometimes it is not.

The trap: thinking a larger alpha always improves predictions. It does not. The price is the added bias, and past some alpha it is not worth paying. The authors say selecting a good value is critical and use cross-validation to pick it.

Prof Rod's rule: never choose alpha by looking at training error. Pick the one that scores best on held-out data.

James, Witten, Hastie, and Tibshirani, An Introduction to Statistical Learning, 2nd ed., Section 6.2.1, Equation 6.5, pp. 237–239; scikit-learn Ridge documentation