Tutorials › Exam PA - Predictive Analytics › Intercepts and Centering in Lasso Models

Exam PA · Lasso Selection and Elastic Net · Tutorial 434 of 966

Intercepts and Centering in Lasso Models

Understand how centering changes lasso intercepts while preserving slope estimates under the usual unpenalized-intercept convention.

Advanced 10 min read

What You'll Learn

  • State the standard lasso objective with an unpenalized intercept.
  • Derive the intercept estimate for fixed penalized slopes.
  • Explain why centering predictors and responses can leave lasso slopes unchanged.
  • Translate fitted intercepts between centered and original variables.
  • Identify errors caused by penalizing or misinterpreting the intercept.

Why the Intercept Is Treated Differently

The lasso shrinks selected slope coefficients to control model complexity. The intercept has a different role: it sets the model’s baseline prediction. Penalizing it would make that baseline depend on the arbitrary location of the response scale, rather than on the strength of the predictor relationships. For this reason, the usual lasso model includes an intercept but does not penalize it.

Centering is closely connected to this convention. Subtracting a predictor’s mean changes where zero is located, and subtracting the response mean changes the baseline. With an unpenalized intercept, these changes can be absorbed by the intercept without changing the fitted slopes, provided the model and penalty are otherwise unchanged.

Definition: For observations \(i=1,\ldots,n\), the standard lasso objective with an intercept is $$ \min_{\beta_0,\boldsymbol{\beta}}\left\{ \frac{1}{2n}\sum_{i=1}^n \left(y_i-\beta_0-\sum_{j=1}^p x_{ij}\beta_j\right)^2 +\lambda\sum_{j=1}^p|\beta_j| \right\}. $$ Here, \(\beta_0\) is the intercept, \(\boldsymbol{\beta}=(\beta_1,\ldots,\beta_p)\) are the slopes, and \(\lambda\geq 0\) controls the penalty. The intercept is excluded from the penalty. This convention and the factor \(1/(2n)\) are stated explicitly because software and references may use other objective scalings.

A slope coefficient describes the change in the fitted response associated with a one-unit increase in its predictor, holding the other predictors fixed. In a lasso fit, that coefficient is subject to shrinkage and may be set to zero. The intercept is the fitted response when all predictors equal zero. That value may be outside the observed data range, so centering often gives the intercept a more useful baseline interpretation.

Finding the Intercept for Fixed Slopes

Write \(\bar{y}=n^{-1}\sum_i y_i\) and \(\bar{x}_j=n^{-1}\sum_i x_{ij}\). For any fixed slopes, the penalty does not involve \(\beta_0\). Differentiating the squared-error term with respect to the intercept and setting the derivative equal to zero gives the fitted intercept.

$$ \frac{\partial}{\partial\beta_0} \left\{\frac{1}{2n}\sum_{i=1}^n (y_i-\beta_0-\boldsymbol{x}_i^\mathsf{T}\boldsymbol{\beta})^2\right\} =-\frac{1}{n}\sum_{i=1}^n (y_i-\beta_0-\boldsymbol{x}_i^\mathsf{T}\boldsymbol{\beta})=0, $$
$$ \widehat{\beta}_0 =\bar{y}-\sum_{j=1}^p\bar{x}_j\widehat{\beta}_j. $$

This is the intercept estimate conditional on the fitted slopes, including lasso slopes. It ensures that the residuals sum to zero. In particular, if every predictor has been centered so that \(\bar{x}_j=0\), then \(\widehat{\beta}_0=\bar{y}\). If both predictors and response have been centered, the intercept in those centered coordinates is zero.

Derivation: For fixed slopes, let \(r_i=y_i-\beta_0-\boldsymbol{x}_i^\mathsf{T}\boldsymbol{\beta}\). The derivative of \(r_i^2/(2n)\) with respect to \(\beta_0\) is \(-r_i/n\). The penalty is constant in \(\beta_0\), so it contributes no derivative. At the minimum, \(\sum_i r_i=0\). Substituting the definitions of the sample means into this equality gives \(\beta_0=\bar{y}-\sum_j\bar{x}_j\beta_j\). Thus the intercept adjusts to the means without being shrunk by \(\lambda\).

What Centering Changes—and What It Leaves Alone

Suppose the predictors are replaced by centered predictors \(x_{ij}^{c}=x_{ij}-\bar{x}_j\), while the response is left unchanged. Then $$ \beta_0+\sum_j x_{ij}\beta_j =\left(\beta_0+\sum_j\bar{x}_j\beta_j\right) +\sum_j x_{ij}^{c}\beta_j. $$ The slopes are the same in the two coordinate systems, while the intercept in the centered-predictor model is \(\bar{y}\). To express that fit using the original predictors, the intercept becomes \(\bar{y}-\sum_j\bar{x}_j\beta_j\).

Centering the response as well replaces \(y_i\) with \(y_i^c=y_i-\bar{y}\). If both predictors and response are centered, the corresponding intercept is zero. To recover predictions on the original response scale, add \(\bar{y}\) back to the fitted centered response. These transformations preserve the slopes because they change only additive constants and the intercept is free to adjust.

The invariance depends on the stated conditions: the intercept is included and unpenalized, the same observations and predictors are used, and the slope penalty is unchanged. It need not hold if the intercept is penalized, omitted, or if the predictors are rescaled and that changes their relative penalty. Scaling is a separate modeling choice; centering alone is a shift, not a rescaling.

Worked Example: A Centered Predictor and an Unchanged Lasso Slope

A hypothetical portfolio model has one predictor \(x=(-2,-1,1,2)\) and responses \(y=(1,2,4,5)\). Use the objective above with \(\lambda=0.5\). Find the lasso slope and intercept, then check the fit.

Method. The predictor is already centered, and the response mean is \(\bar{y}=(1+2+4+5)/4=3\). For one centered predictor, define \(c=\sum_i x_i^2/n\) and \(z=\sum_i x_i(y_i-\bar{y})/n\). The slope minimizes \(c\beta^2/2-z\beta+\lambda|\beta|\), so for positive \(z\) its solution is \(\widehat{\beta}=(z-\lambda)/c\) when \(z>\lambda\).

Compute \(c=(4+1+1+4)/4=10/4=2.5\). The centered responses are \((-2,-1,1,2)\), so \(z=[(-2)(-2)+(-1)(-1)+(1)(1)+(2)(2)]/4=10/4=2.5\). Since \(z=2.5>0.5\), \(\widehat{\beta}=(2.5-0.5)/2.5=0.8\). The intercept is \(\widehat{\beta}_0=\bar{y}=3\).

The fitted values are \(3+0.8x=(1.4,2.2,3.8,4.6)\). The residuals are \((-0.4,-0.2,0.2,0.4)\), which sum to zero, and their squared sum is \(0.16+0.04+0.04+0.16=0.40\). The objective value is \(0.40/(2\cdot4)+0.5(0.8)=0.05+0.40=0.45\). The calculation checks the fitted intercept and objective. The common mistake avoided here is applying the penalty to the intercept as if it were another slope.

Worked Example: Translating a Centered-Predictor Fit

A hypothetical study has \(x=(1,2,3,4)\) and \(y=(2,3,5,6)\). Fit a one-predictor lasso with \(\lambda=0.5\), using the unpenalized intercept. Find the slope and report the intercept both with the centered predictor and with the original predictor.

Method. Centering the predictor gives \(x^c=(-1.5,-0.5,0.5,1.5)\). The response mean is \(\bar{y}=4\), so \(y^c=(-2,-1,1,2)\). Here \(c=\sum_i(x_i^c)^2/4=(2.25+0.25+0.25+2.25)/4=5/4=1.25\), and \(z=\sum_i x_i^cy_i^c/4=(3+0.5+0.5+3)/4=7/4=1.75\).

Since \(z>\lambda\), the lasso slope is \(\widehat{\beta}=(1.75-0.5)/1.25=1.25/1.25=1\). In the centered-predictor model with the uncentered response, the intercept is \(\bar{y}=4\), giving fitted values \(4+x^c=(2.5,3.5,4.5,5.5)\).

The original predictor mean is \(\bar{x}=2.5\). Thus the equivalent intercept on the original predictor scale is \(4-(1)(2.5)=1.5\), and the model is \(\widehat{y}=1.5+x\). Its fitted values are again \((2.5,3.5,4.5,5.5)\). The residuals are \((-0.5,-0.5,0.5,0.5)\), with sum zero and squared sum \(1\); the objective is \(1/8+0.5=0.625\). The check confirms that centering changed the intercept’s coordinate, not the predictions or slope. The trap is confusing the intercept \(4\) for the centered-predictor model with the intercept \(1.5\) for the original-predictor model.

Worked Example: Centering the Response and Recovering Predictions

For a hypothetical three-observation model, let \(x=(2,4,6)\), \(y=(5,7,10)\), and \(\lambda=1/3\). Center both variables to find the lasso slope. Then recover the intercept on the original scales and check the objective.

Method. The means are \(\bar{x}=4\) and \(\bar{y}=22/3\). Therefore \(x^c=(-2,0,2)\) and \(y^c=(-7/3,-1/3,8/3)\). The centered predictor sum of squares per observation is \(c=(4+0+4)/3=8/3\). The cross-product per observation is \(z=[(-2)(-7/3)+(0)(-1/3)+(2)(8/3)]/3=(14/3+16/3)/3=10/3\).

Since \(z>\lambda\), the slope is \(\widehat{\beta}=(10/3-1/3)/(8/3)=3/(8/3)=9/8\). With both variables centered, the fitted intercept is zero. Returning to the original response and predictor scales gives \(\widehat{\beta}_0=\bar{y}-\bar{x}\widehat{\beta}=22/3-4(9/8)=22/3-9/2=17/6\).

The original-scale fitted values are \(17/6+(9/8)x\), or \(61/12,\ 22/3,\ 115/12\). The residuals are \(-1/12,\ -1/3,\ 5/12\). They sum to zero, and their squared sum is \((1+16+25)/144=7/24\). The objective is \((7/24)/6+(1/3)(9/8)=7/144+3/8=61/144\). The calculations verify the back-transformation and objective. The common mistake avoided is reporting the centered-coordinate intercept of zero as the intercept for predictions on the original response scale.

Common Mistakes and Interpretation

Centering conventions are not just bookkeeping. They determine what the intercept means, while the unpenalized-intercept convention protects the fitted slopes from arbitrary shifts of the variable origins. Keep track of which coordinates a reported intercept belongs to, and state whether the response has been centered.

Model coordinatesIntercept estimateInterpretation
Original predictors and response\(\bar{y}-\sum_j\bar{x}_j\widehat{\beta}_j\)Fitted response when original predictors equal zero
Centered predictors, original response\(\bar{y}\)Fitted response at the predictors’ sample means
Centered predictors and centered response0Centered response at the predictors’ sample means
  • Penalizing the intercept: This changes the model. It can shrink the baseline and can make the fit depend on whether the response was shifted before fitting.
  • Mixing coordinate systems: An intercept for centered predictors is not automatically the intercept for the original predictors. Convert it by subtracting \(\sum_j\bar{x}_j\widehat{\beta}_j\).
  • Forgetting to restore the response mean: Predictions from a model fitted to \(y_i-\bar{y}\) are deviations from the response mean. Add \(\bar{y}\) to return to the original response scale.
  • Assuming every data change leaves slopes unchanged: The centering result concerns additive shifts with the same unpenalized intercept and unchanged slope penalty. It does not say that rescaling predictors leaves the lasso fit unchanged.
Key takeaway: In the standard lasso, the intercept is estimated to make residuals sum to zero and is excluded from the penalty. Centering predictors or the response changes the intercept’s coordinate and interpretation; under the stated conditions, it does not change the penalized slope estimates.

Check Your Understanding

For each problem, keep track of the objective convention and the coordinate system used for the intercept.

  1. A one-predictor data set has centered \(x\), response mean \(6\), and fitted lasso slope \(0.7\). What is the fitted intercept when the response is uncentered? (Answer: \(6\).)
  2. A centered-predictor model has intercept \(5\), slope \(2\), and the original predictor mean is \(3\). What is the equivalent intercept using the original predictor? (Answer: \(-1\).)
  3. A model has \(\bar{y}=12\), predictor means \((2,5)\), and fitted slopes \((1.5,-0.4)\). Find the original-coordinate intercept. (Answer: \(11\).)
  4. Both predictors and response are centered, and the fitted slopes are \((0.5,-1)\). What is the fitted intercept in centered coordinates, and what must be added to predictions to restore the original response scale if \(\bar{y}=8\)? (Answer: centered intercept \(0\); add \(8\).)
  5. For \(n=4\), a model uses the objective \(RSS/(2n)+\lambda|\beta_1|\), with an unpenalized intercept. For fixed slopes, the residuals are \((1,-1,2,-2)\). Is the intercept at its minimizing value, and why? (Answer: Yes; the residuals sum to \(0\), the intercept’s first-order condition.)
Clinical Biostats