With several inputs, the least-squares coefficients solve the normal equations $X^{\mathsf{T}}X\mathbf{b} = X^{\mathsf{T}}\mathbf{y}$, and each describes the difference in prediction between cases that differ by one unit in that input and match on the others. A simple slope equals the multiple slope plus each omitted input's coefficient times its slope on the included input. For 442 diabetes patients the BMI slope is 10.23 alone and 6.50 with blood pressure and S5, while $R^2$ rises from 0.344 to 0.480. Collinearity multiplies a coefficient's variance by $\mathrm{VIF}_j = 1/(1 - R_j^2)$, 59.2 for S1. Interactions and polynomial terms keep the model linear in its coefficients, but flexibility overfits: in ten-fold cross-validation the ten-input cubic (285 columns) scores $R^2 = -14.8$, against 0.484 for the linear model.
In the diabetes study of Efron, Hastie, Johnstone and Tibshirani (2004), body mass index (BMI) alone explains 34.4% of the variation in disease progression after one year, as worked out in Simple Linear Regression. The study measured nine other variables at baseline, and some of them are related to progression too: average blood pressure (BP) has a correlation of 0.441 with progression, and the serum measurement S5 has 0.566. S5 is described in the scikit-learn documentation (version 1.9.1, checked November 2026) as "ltg, possibly log of serum triglycerides level". These inputs are also related to each other: BMI and BP have a correlation of 0.395, BMI and S5 0.446. Multiple linear regression uses several inputs at once. It predicts better than any one of them alone, and it answers a different question from a set of simple regressions: what each input is associated with when the others are taken into account.
The model
With $p$ inputs $x_1, \dots, x_p$, the model is
$$y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_p x_p + \varepsilon,$$
and the fitted equation is $\hat{y} = b_0 + b_1 x_1 + \cdots + b_p x_p$. With two inputs the fitted equation describes a plane above the $(x_1, x_2)$ plane, and with more it describes a hyperplane, which cannot be drawn but behaves the same way. Fitted to BMI, BP and S5, least squares gives
$$\widehat{\text{progression}} = -334.88 + 6.500\,\text{BMI} + 0.903\,\text{BP} + 49.58\,\text{S5}.$$
A patient with a BMI of 30, a BP of 100 and an S5 of 5.0 is predicted to have progression $-334.88 + 6.500 \times 30 + 0.903 \times 100 + 49.58 \times 5.0 = 198.3$. Every input needs a value; a prediction from this model cannot leave one out.
Matrix form
Writing the model for all $n$ observations at once makes the algebra compact (Gelman, Hill and Vehtari, 2020, §10.7). Stack the outputs in a vector $\mathbf{y}$ of length $n$, and the inputs in an $n \times (p+1)$ design matrix $X$ whose first column is all ones, for the intercept, and whose other columns are the inputs. With the coefficients in a vector $\mathbf{b}$, the fitted values are $\hat{\mathbf{y}} = X\mathbf{b}$, and
$$\mathrm{RSS}(\mathbf{b}) = (\mathbf{y} - X\mathbf{b})^{\mathsf{T}}(\mathbf{y} - X\mathbf{b}).$$
Deriving the least-squares coefficients
Expanding the product,
$$\mathrm{RSS}(\mathbf{b}) = \mathbf{y}^{\mathsf{T}}\mathbf{y} - 2\,\mathbf{b}^{\mathsf{T}} X^{\mathsf{T}}\mathbf{y} + \mathbf{b}^{\mathsf{T}} X^{\mathsf{T}} X\,\mathbf{b}.$$
Its gradient with respect to $\mathbf{b}$ is $-2X^{\mathsf{T}}\mathbf{y} + 2X^{\mathsf{T}}X\mathbf{b}$, and setting that to zero gives the normal equations
$$X^{\mathsf{T}} X\, \mathbf{b} = X^{\mathsf{T}} \mathbf{y}.$$
If the columns of $X$ are linearly independent, $X\mathbf{v} \ne \mathbf{0}$ for every nonzero $\mathbf{v}$, so $\mathbf{v}^{\mathsf{T}}X^{\mathsf{T}}X\mathbf{v} = \lVert X\mathbf{v}\rVert^2 > 0$: the matrix $X^{\mathsf{T}}X$ is positive definite and therefore invertible. For any $\mathbf{b}$ and a solution $\hat{\mathbf{b}}$ of the normal equations, expanding as above gives $\mathrm{RSS}(\mathbf{b}) = \mathrm{RSS}(\hat{\mathbf{b}}) + (\mathbf{b} - \hat{\mathbf{b}})^{\mathsf{T}}X^{\mathsf{T}}X(\mathbf{b} - \hat{\mathbf{b}})$, because the cross term is $-2(\mathbf{b} - \hat{\mathbf{b}})^{\mathsf{T}}X^{\mathsf{T}}(\mathbf{y} - X\hat{\mathbf{b}}) = 0$. The stationary point is therefore the unique minimum, and
$$\mathbf{b} = (X^{\mathsf{T}} X)^{-1} X^{\mathsf{T}} \mathbf{y}.$$
With $p = 1$ these are exactly the two equations derived in Simple Linear Regression. The same equations, for scoring documents by weighted fields, appear in Zones and Weighted Zone Scoring.
The normal equations can be rewritten as $X^{\mathsf{T}}(\mathbf{y} - X\mathbf{b}) = X^{\mathsf{T}}\mathbf{e} = \mathbf{0}$: the residual vector is orthogonal to every column of $X$. Geometrically, $\hat{\mathbf{y}}$ is the orthogonal projection of $\mathbf{y}$ onto the space spanned by the columns, the closest point to $\mathbf{y}$ that any choice of coefficients can reach. The Geometry of Least Squares proves this picture and derives from it the omitted-variable identity below in general. Because the column of ones is among them, the residuals sum to zero, as in simple regression.
For the model with BMI, BP and S5, the matrices are
$$X^{\mathsf{T}}X = \begin{pmatrix} 442 & 11{,}658.1 & 41{,}834.0 & 2{,}051.5 \\ 11{,}658.1 & 316{,}099.9 & 1{,}114{,}060.2 & 54{,}564.1 \\ 41{,}834.0 & 1{,}114{,}060.2 & 4{,}043{,}826.5 & 195{,}422.5 \\ 2{,}051.5 & 54{,}564.1 & 195{,}422.5 & 9{,}642.2 \end{pmatrix}, \qquad X^{\mathsf{T}}\mathbf{y} = \begin{pmatrix} 67{,}243.0 \\ 1{,}861{,}676.5 \\ 6{,}571{,}949.8 \\ 322{,}152.6 \end{pmatrix}.$$
The first row holds $n$ and the sums of the three inputs; the other entries are sums of products. Solving the system gives the coefficients above, $(-334.8812, 6.5001, 0.9030, 49.5771)$, the same values scikit-learn returns. In practice software does not form the inverse explicitly. It solves the system with a matrix factorization, which is faster and more accurate when the columns are nearly dependent; scikit-learn's LinearRegression calls SciPy's lstsq (scikit-learn 1.5.2). The Geometry of Least Squares compares the factorizations in its section on computing the projection, and Worked problem 3 shows what near-dependence does to a computed result.
Holding the other inputs constant
The coefficient of BMI changes as inputs are added:
| Model | BMI coefficient (SE) | BP coefficient | S5 coefficient | $R^2$ | Adjusted $R^2$ |
|---|---|---|---|---|---|
| BMI | 10.233 (0.674) | 0.3439 | 0.3424 | ||
| BMI + BP | 8.519 (0.705) | 1.385 | 0.3960 | 0.3932 | |
| BMI + BP + S5 | 6.500 (0.697) | 0.903 | 49.58 | 0.4801 | 0.4765 |
Each multiple-regression coefficient describes the difference in predicted progression between patients who differ by one unit in that input and are the same in the other inputs in the model. Among patients with the same BP and S5, a one-unit difference in BMI goes with a difference of 6.50 in predicted progression. Among all patients, ignoring BP and S5, it goes with 10.23. The two numbers answer different questions, and both are correct.
The simple slope is larger because patients with higher BMI tend also to have higher BP, and higher BP goes with higher progression. Comparing patients by BMI alone, the comparison picks up some of the BP difference too. This is exact, not just a story. Fit the two-input model $\hat{y} = b_0 + b_1 x_1 + b_2 x_2$, and let $\delta$ be the slope of the simple regression of $x_2$ on $x_1$. The simple slope of $y$ on $x_1$ is $\sum (x_{1i} - \bar{x}_1)\,y_i / S_{x_1x_1}$. Substitute $y_i = b_0 + b_1 x_{1i} + b_2 x_{2i} + e_i$ into the numerator and take the four terms in turn. The constant contributes $b_0\sum (x_{1i} - \bar{x}_1) = 0$. The second term contributes $b_1\sum (x_{1i} - \bar{x}_1)x_{1i} = b_1 S_{x_1x_1}$, and the third contributes $b_2\sum (x_{1i} - \bar{x}_1)x_{2i} = b_2\,\delta\,S_{x_1x_1}$, by the definition of $\delta$. The residuals contribute $\sum (x_{1i} - \bar{x}_1)\,e_i = 0$, by the normal equations of the two-input fit: the residuals are orthogonal to the column of ones and to $x_1$. Dividing by $S_{x_1x_1}$ gives
$$b_1^{\text{simple}} = b_1 + b_2\,\delta.$$
For the diabetes data, the slope of BP on BMI is $\delta = 1.2379$, and $8.5190 + 1.3847 \times 1.2379 = 10.2331$, the simple slope exactly. The difference between the simple and multiple slopes is the other input's coefficient times how strongly the two inputs move together. This is the omitted-variable effect: leaving out an input that is related to both the output and an included input shifts the included input's coefficient. Worked problem 2 extends the identity to two omitted inputs, and the Frisch–Waugh–Lovell theorem (Theorem 5 of The Geometry of Least Squares) gives the general form: each multiple-regression coefficient is the simple slope of $y$ on what is left of its input after regressing it on the others.
Gelman, Hill and Vehtari (2020, §10.2) recommend reading coefficients as comparisons between units rather than as the effect of changing one input in one unit, because the data alone describe comparisons between patients, not what would happen if one patient's BMI changed. They also point out that "holding the others constant" is sometimes impossible: if a model contains both $x$ and $x^2$, one cannot change $x$ with $x^2$ held fixed. The interaction and polynomial sections below meet this directly.
R squared and adjusted R squared
$R^2 = 1 - \mathrm{RSS}/\mathrm{TSS}$ keeps its meaning from simple regression, the share of variation in the output accounted for by the model, and with several inputs it equals the squared correlation between $y$ and $\hat{y}$ (James, Witten, Hastie and Tibshirani, 2021, §3.2.2; proved as Theorem 3 of The Geometry of Least Squares). But it can never fall when an input is added, because least squares could always set the new coefficient to zero and keep the old RSS; James et al. (2021, §3.2.2) note that $R^2$ always increases when variables are added, even weakly related ones. The adjusted $R^2$ charges for each coefficient:
$$R^2_{\text{adj}} = 1 - \frac{\mathrm{RSS}/(n - p - 1)}{\mathrm{TSS}/(n - 1)},$$
which falls when an added input reduces RSS too little to pay for its extra coefficient (James et al., 2021, §6.1.3). With all ten baseline variables, $R^2 = 0.5177$ and the adjusted value is 0.5066, against 0.4801 and 0.4765 for the three-input model. Adding seven inputs buys about four points of explained variation (three after adjustment). Adjusted $R^2$ is a rough guide; the honest test of a model's predictions is on data it was not fitted to, discussed under overfitting below.
Categorical inputs
Inputs need not be numerical. The diabetes data record sex as 1 or 2; the documentation does not say which code means which. A categorical input with two levels enters the model as an indicator (or dummy) variable that is 1 for one level and 0 for the other. The level coded 0 is the baseline, and the indicator's coefficient is the difference between the two levels. For a variable with $k$ levels, $k - 1$ indicators are used, one for each level except the baseline (James et al., 2021, §3.3.1). Including an indicator for every level would make the columns linearly dependent, since they would sum to the column of ones, and the normal equations would have no unique solution. In machine learning, building indicators for a categorical variable is called one-hot encoding (James et al., 2021, §3.3.1). The term refers to the inputs. A two-class output, as in Logistic Regression, is simply coded 0 and 1.
With an indicator for sex 2 as the only input, the fit is $\hat{y} = 149.02 + 6.65 \times \text{indicator}$: the 207 patients coded 2 average 155.67 and the 235 coded 1 average 149.02. The difference, with a standard error of 7.35, is indistinguishable from zero ($p = 0.37$). (The Normal Linear Model derives these standard errors and tests.) Adding the indicator to the model with BMI, BP and S5 changes its coefficient to $-13.04$ (standard error 5.46, $p = 0.017$): among patients with the same BMI, BP and S5, those coded 2 are predicted to progress 13 units less. The sign reversed. Patients coded 2 have higher average BP (98.2 against 91.5), BMI and S5, which raise their predicted progression; once those differences are accounted for, what remains is lower.
Collinearity
When inputs are strongly correlated, the data contain little information about each one's separate contribution. Two of the diabetes serum measurements, S1 (total cholesterol) and S2 (LDL cholesterol), have a correlation of 0.897. In the model with all ten inputs, S1's coefficient is $-1.090$ with standard error 0.573. Added alone to the model with BMI, BP and S5, its coefficient is $-0.284$ with standard error 0.089. The standard error is six times larger in the full model, because there S2, S3 and S4 (HDL and the ratio of total cholesterol to HDL) can largely stand in for S1.
The variance inflation factor measures this. Regress input $j$ on all the other inputs, call that fit's $R^2_j$, and set
$$\mathrm{VIF}_j = \frac{1}{1 - R^2_j}.$$
It is the factor by which the variance of $b_j$ is inflated compared with a model where input $j$ is uncorrelated with the rest (Worked problem 1 derives this and checks it on S1); James et al. (2021, §3.3.3) give values above 5 or 10 as a common sign of a problem. In the full diabetes model, the VIFs are 59.2 for S1, 39.2 for S2, 15.4 for S3, 10.1 for S5 and 8.9 for S4, and between 1.2 and 1.5 for age, sex, BMI, BP and S6. Collinearity does not harm predictions for new cases whose combination of inputs resembles the training data; a combination unlike any in the data is an extrapolation even when each input is in range (Introduction to Regression, Worked problem 2). It makes individual coefficients unstable and hard to interpret, so a coefficient with a large VIF should not be read as that input's separate effect. Remedies are to drop or combine redundant inputs, or to use regularized methods such as ridge regression, which shrink the coefficients toward zero and reduce their variance (James et al., 2021, §6.2).
Interactions
The model so far is additive: the BMI slope is the same at every BP. An interaction term, the product of two inputs, lets one input's slope depend on another. Adding $\text{BMI} \times \text{BP}$:
$$\widehat{\text{progression}} = 66.45 - 1.617\,\text{BMI} - 1.489\,\text{BP} + 0.1068\,\text{BMI} \times \text{BP}.$$
Collecting the BMI terms, the BMI slope at a given BP is $-1.617 + 0.1068 \times \text{BP}$: 6.93 at a BP of 80, 8.53 at 95 and 10.14 at 110. The values 80 and 110 lie close to the 10th and 90th percentiles of BP in the data, 78.0 and 113.0. Higher BMI goes with more progression in all of them, and more steeply among patients with higher blood pressure. The interaction coefficient has standard error 0.0442 ($p = 0.016$), and $R^2$ rises from 0.3960 to 0.4040.
The individual coefficients of BMI and BP in this model, $-1.617$ and $-1.489$, look alarming but describe slopes at a BP or BMI of zero, far outside the data, and should not be read alone. Centering the inputs at their means before forming the product makes the main coefficients describe slopes at average values, which is easier to interpret (Gelman et al., 2020, §12.2). It is standard to keep both inputs in a model whenever their product is included, even if their own coefficients are not significant (the hierarchical principle; James et al., 2021, §3.3.2).
Polynomial terms
A straight line cannot follow a curve, but a model that is linear in its coefficients can. Adding a squared input gives
$$\hat{y} = b_0 + b_1 x + b_2 x^2,$$
which is a parabola in $x$. It is still a linear regression, because $\hat{y}$ is a linear combination of the columns $1$, $x$ and $x^2$ with unknown coefficients, and the normal equations solve for them as before. The second of Anscombe's (1973) datasets, which a straight line fits with $R^2 = 0.666$, is fitted by a quadratic with $R^2 = 1.00000$ to five decimals:
$$\hat{y} = -5.9957 + 2.7808\,x - 0.12671\,x^2.$$
With several inputs, a polynomial of degree $d$ includes every product of inputs whose powers add up to at most $d$. For two inputs and degree 2 the columns are $1, x_1, x_2, x_1^2, x_1 x_2, x_2^2$: the squares bend the surface and the product is an interaction. The number of columns, including the constant, is $\binom{p + d}{d}$. Each column is a monomial $x_1^{a_1}\cdots x_p^{a_p}$ with $a_1 + \cdots + a_p \le d$. Adding a slack exponent $a_0 = d - \sum_j a_j$ turns these into the solutions of $a_0 + a_1 + \cdots + a_p = d$ in nonnegative integers, which number $\binom{d + p}{p} = \binom{p + d}{d}$ (arrange $d$ units and $p$ dividers in a row). With 3 inputs that is 10 for degree 2 and 20 for degree 3; with 10 inputs it is 66 and 286.
More columns, worse predictions
Each added column lowers the RSS on the data the model is fitted to, so training $R^2$ always improves. Whether predictions improve for new patients is a separate question, which cross-validation answers by fitting on part of the data and measuring on the rest. Here the 442 patients are split into ten folds at random (with a fixed seed); each fold in turn is held out, the model is fitted to the other nine, and $R^2$ is computed on the held-out fold. The table reports the mean of the ten held-out values. The method is explained in Cross-Validation, and for classifiers in Evaluating Classifiers.
| Inputs | Degree | Columns (without constant) | Training $R^2$ | Cross-validated $R^2$ |
|---|---|---|---|---|
| BMI, BP, S5 | 1 | 3 | 0.480 | 0.459 |
| BMI, BP, S5 | 2 | 9 | 0.495 | 0.458 |
| BMI, BP, S5 | 3 | 19 | 0.514 | 0.448 |
| all ten | 1 | 10 | 0.518 | 0.484 |
| all ten | 2 | 65 | 0.592 | 0.408 |
| all ten | 3 | 285 | 0.798 | −14.792 |
With three inputs, the quadratic and cubic terms raise training $R^2$ slightly and leave cross-validated $R^2$ flat or lower: the relationships here have little curvature. With all ten inputs, degree 2 already predicts worse than the plain linear model, and degree 3, with 285 columns fitted to about 398 patients in each training split, fits the training data far better ($R^2 = 0.798$) and new patients catastrophically. Its held-out $R^2$ averages $-14.8$ over the ten folds (median $-3.74$). A held-out $R^2$ of $-14.8$ means squared errors 15.8 times as large as those of simply predicting the held-out fold's mean: $R^2$ computed on new data has no lower bound. This is overfitting: a model flexible enough to fit the noise in its training data predicts new data worse, the subject of The Bias-Variance Tradeoff. (Sex takes only the values 1 and 2, so its square equals $3 \times \text{sex} - 2$, a combination of columns already present, and 11 of the 285 columns are redundant; least squares still finds a solution, but it is no better behaved.) The last cross-validated value is $-14.792$ once those redundant columns are removed. With them left in, 11 of the design's columns are exact combinations of others, and how a solver treats them in floating point decides the later digits: a rerun with scikit-learn 1.5.2 gave $-14.800$ where the original run gave $-14.792$, from the same data and folds. Worked problem 3 finds the cause.
Choosing which inputs and terms to include is model selection, covered in Model Selection. For choosing among many candidate inputs in text classification, the Academics section's Feature Selection describes the standard filters.
Worked problems
The problems extend the article on its own data. Every number is recomputed, with assertions, in the review-pass block of tools/experiments/data-science/multiple-linear-regression.py.
Problem 1 (where the variance inflation factor comes from). Show that $\mathrm{Var}(b_j) = \sigma^2/[S_{jj}(1 - R_j^2)]$, where $S_{jj}$ is the sum of squared deviations of input $j$ from its mean, and check it on the standard error of S1 in the ten-input model.
Solution. By the Frisch–Waugh–Lovell theorem (Theorem 5 of The Geometry of Least Squares), $b_j$ is the simple slope of $y$ on $\mathbf{r}_j$, the residual of input $j$ after regressing it on the other inputs and the constant. A slope on a single centered column $\mathbf{r}_j$ has variance $\sigma^2/\lVert\mathbf{r}_j\rVert^2$, as derived for one input in Simple Linear Regression. The residual sum of squares of that auxiliary regression is $\lVert\mathbf{r}_j\rVert^2 = S_{jj}(1 - R_j^2)$, by the definition of $R_j^2$. Dividing the variance by its value for an input uncorrelated with the rest, $\sigma^2/S_{jj}$, leaves $1/(1 - R_j^2) = \mathrm{VIF}_j$. For S1, the ten-input model has $\mathrm{RSE} = 54.15$, $S_{11} = 528{,}193$ and $R_1^2 = 0.9831$, so
$$\mathrm{SE}(b_{\text{S1}}) = \frac{54.15}{\sqrt{528{,}193 \times (1 - 0.9831)}} = 0.5733,$$
the value in the fitted model. Without collinearity it would be $54.15/\sqrt{528{,}193} = 0.0745$. The ratio, 7.69, is $\sqrt{59.2}$: a VIF of 59 multiplies the standard error by almost eight.
Problem 2 (two omitted inputs). The simple BMI slope is 10.2331 and the BMI coefficient in the model with BP and S5 is 6.5001. Split the difference between the two omitted inputs.
Solution. Repeat the derivation of the omitted-variable identity with $y_i = b_0 + b_1 x_{1i} + b_2 x_{2i} + b_3 x_{3i} + e_i$. Each extra input contributes its coefficient times its own simple slope on BMI, and the residual term vanishes as before, so
$$b_1^{\text{simple}} = b_1 + b_2\,\delta_{\text{BP}} + b_3\,\delta_{\text{S5}}.$$
The slopes of BP and S5 on BMI are $\delta_{\text{BP}} = 1.2379$ and $\delta_{\text{S5}} = 0.05275$. Then $6.5001 + 0.9030 \times 1.2379 + 49.5771 \times 0.05275 = 6.5001 + 1.1177 + 2.6153 = 10.2331$. S5 accounts for more of the gap than BP, although its slope on BMI looks small, because its coefficient is large in its own units.
Problem 3 (why the degree-3 result depends on the solver). The ten-input cubic model's cross-validated $R^2$ was $-14.792$ in the original run and $-14.800$ in a rerun on the same data and folds. Find the cause and decide what can be reported.
Solution. The design has 286 columns with the constant, but its rank is 275. Because sex takes only the values 1 and 2, $\text{sex}^2 = 3\,\text{sex} - 2$ and $\text{sex}^3 = 7\,\text{sex} - 6$ for every patient. So $\text{sex}^2$, $\text{sex}^3$ and $\text{sex}^2$ times each of the other nine inputs are exact combinations of other columns: 11 redundant columns. In exact arithmetic this changes nothing, because held-out patients satisfy the same identities, so every least-squares solution gives the same predictions. In floating point it is exactly the step that fails. With each column scaled to unit length, the 11 redundant directions have computed singular values between about $1 \times 10^{-17}$ and $1 \times 10^{-16}$ of the largest (first training fold), while the smallest genuine one is about $2 \times 10^{-9}$. A least-squares solver discards a direction whose singular value falls below a cutoff near machine precision, and values this close to the cutoff are discarded or kept according to rounding, differently by library. When a redundant direction is kept, its coefficient is arbitrary and large, and held-out rows, which satisfy the identities only to rounding, pick up noise from it. On all 286 columns (NumPy 2.4.6, SciPy 1.17.1), NumPy's lstsq gives $-14.796$, SciPy's default lstsq $-14.779$, SciPy's QR-based driver $-14.792$ and scikit-learn 1.5.2 $-14.800$.
Removing the 11 redundant columns settles the matter. With the remaining 275 columns, which have full rank, QR, NumPy's lstsq and both SciPy drivers all give a cross-validated $R^2$ of $-14.792$ (median $-3.740$), on raw inputs and on inputs standardized within each training fold alike. The training $R^2$, 0.798, is the same in every version. So $-14.792$ is the well-determined value, the one in the table. The remedy is to remove exact redundancies before fitting, for example by entering a two-level input as one indicator and not forming its powers. Scaling the columns guards against a different hazard: on the raw scale some genuine singular values are small enough that a solver with a looser cutoff discards them, and a cutoff of $10^{-12}$ in SciPy's lstsq gives $-12.77$.
Problem 4 (centering an interaction). Refit the BMI by BP interaction model with both inputs centered at their means, and relate the new coefficients to the old.
Solution. With $c_1 = \text{BMI} - 26.38$ and $c_2 = \text{BP} - 94.65$, the fit is
$$\widehat{\text{progression}} = 149.56 + 8.495\,c_1 + 1.329\,c_2 + 0.1068\,c_1 c_2.$$
Expanding $c_1c_2 = \text{BMI}\cdot\text{BP} - 94.65\,\text{BMI} - 26.38\,\text{BP} + 26.38 \times 94.65$ shows that the two models span the same columns, so the fitted values, $R^2$ and the interaction coefficient are unchanged. The BMI coefficient becomes the old one plus the interaction times the mean BP: $-1.617 + 0.1068 \times 94.65 = 8.495$, the BMI slope for a patient of average BP. The intercept, 149.56, is the predicted progression for a patient of average BMI and BP. Centering changed no prediction. It made every coefficient describe a patient inside the data, as Gelman et al. (2020, §12.2) recommend.
Open questions
- Which sex code is which? Neither the scikit-learn documentation nor the data page it cites (Efron et al.'s data at North Carolina State University) labels the codes 1 and 2. The study's own records would settle it, and with it the reading of the $-13.04$ coefficient.
- Is the BMI by BP interaction real? It is one of 45 possible pairwise interactions among ten inputs, and this article fits only that one. Fitting all 45, correcting for multiple testing (Multiple Testing), and checking whether the BMI by BP term improves cross-validated error would show whether it survives.
- Can shrinkage rescue the polynomial models? Ridge and Lasso Regression shows that shrinkage helps the ten-input linear model only with small training sets. Whether a ridge or lasso fit of the degree-2 and degree-3 columns, with the penalty chosen inside each training fold, beats the linear model's cross-validated $R^2$ of 0.484 is not known for these data. A nested cross-validation over 30 seeds would settle it.
Where it leads
Every model so far predicts a number. Logistic Regression keeps the linear predictor of this article but uses it to model the probability of a yes-or-no outcome, fitted by maximum likelihood instead of least squares. The Statistics collection proves what this article used: The Geometry of Least Squares for the normal equations and the omitted-variable identity in general, The Normal Linear Model and The General Linear Hypothesis for the $t$ and $F$ tests of coefficients, and Ridge and Lasso Regression for the remedy for collinearity on these same patients.
In Python
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import KFold, cross_val_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import PolynomialFeatures
data = load_diabetes(scaled=False)
X, y = data.data, data.target
X3 = X[:, [2, 3, 8]] # BMI, BP, S5
model = LinearRegression().fit(X3, y)
print(model.intercept_, model.coef_) # -334.88, [6.500 0.903 49.58]
print(model.predict([[30, 100, 5.0]])) # 198.3
folds = KFold(10, shuffle=True, random_state=0)
for degree in (1, 2, 3):
poly = make_pipeline(PolynomialFeatures(degree, include_bias=False), LinearRegression())
print(degree, cross_val_score(poly, X, y, cv=folds, scoring="r2").mean())
PolynomialFeatures builds the columns of powers and products, and LinearRegression fits a linear model to whatever columns it receives; it neither knows nor needs to know that some are squares of others. Wrapping the two in a pipeline ensures that, during cross-validation, the columns for each held-out fold are built in the same way as for the training folds. The numbers in this article are computed by tools/experiments/data-science/multiple-linear-regression.py in the site's repository, with scikit-learn 1.5.2 (checked against the 1.9.1 documentation, November 2026).
References
- Anscombe, F. J. (1973). Graphs in statistical analysis. The American Statistician, 27(1), 17–21. record · 4 pages
- Efron, B., Hastie, T., Johnstone, I., and Tibshirani, R. (2004). Least angle regression. The Annals of Statistics, 32(2), 407–499. record · 21 pages
- Gelman, A., Hill, J., and Vehtari, A. (2020). Regression and Other Stories. Cambridge University Press. record · 7 pages
- James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. record · 39 pages
Reviewed: verified, 23 Nov 2026 · citations checked, 23 Nov 2026 · editorial review, 23 Nov 2026 · 7 revisions