# More Than One Feature

A linear regression with several features learns one coefficient for each, read as the change in the guess for one more unit of that feature with the others held the same; a coefficient's size isn't its importance when the units differ, and features that move together, such as bedrooms and size, share the credit.

Journeyman · AI Basics · Python · Updated November 19, 2026

By Gregor Dzierzon

## After this lesson you can

- Train a linear regression on several features and read each coefficient as the change in the guess with the other features held the same
- Explain why a coefficient's size isn't its importance when the units differ, and how features that move together share the credit

## Key takeaways

- With several features in X, a linear regression learns one coefficient per feature, in the order of X's columns.
- Read each coefficient as the change in the guess for one more unit of that feature, with every other feature held the same.
- A coefficient's size depends on its feature's units, so a big one isn't a more important one. Multiplying each by its feature's standard deviation puts them on one scale.
- Features that move together, such as bedrooms and size, share the credit, so either one's coefficient can change a lot when the other is added.
- A coefficient says what the model learned from the data, not what causes a price.

Two Maple Grove homes are both 2,000 square feet, but one has a two-car garage and was built three years ago, and the other has no garage and is sixty years old. A line that only knows the size gives them the same price, and no buyer would. Real guesses look at several things at once, and so will most models you build. Reading what such a model learned takes more care than reading one slope, and the mistakes people make here end up in reports and decisions.

The example is Maple Grove Homes' `home_sales.csv`, from *Exercise: Home Price Guesser*. Each code block is one notebook cell, run in order: the first one loads the data, and the others use what it made.

## One coefficient per feature

Nothing in the three steps changes: `X` gets more columns. This time `train_test_split` is given the whole table, and it hands back two tables, the training homes and the test homes, so any of their columns can be used:

```python
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

homes = pd.read_csv("home_sales.csv")
train, test = train_test_split(homes, test_size=0.2, random_state=42)

features = ["size_sqft", "garage_spaces", "age_years"]
model = LinearRegression()
model.fit(train[features], train["sale_price"])
for feature, coef in zip(features, model.coef_):
    print(feature, round(coef, 2))
print("intercept", round(model.intercept_, 2))
```

```text
size_sqft 135.57
garage_spaces 7885.29
age_years -821.65
intercept 49209.98
```

`coef_` now holds three numbers, one for each feature, in the order of `X`'s columns. A guess is the intercept plus each coefficient times its feature, added up: about $49,210, plus $135.57 a square foot, plus $7,885 a garage space, minus $822 a year of age. The seed script planted $50,000, $135, $9,000 and −$800. The model came close from 320 sales, not exactly: the random wobble in every price hides the planted rule a little.

## "With the others held the same"

Read each coefficient as the change in the guess for one more unit of that feature, **with every other feature held the same**. Two homes alike in every way but one garage space show it:

```python
two_homes = pd.DataFrame({
    "size_sqft": [2000, 2000],
    "garage_spaces": [1, 2],
    "age_years": [10, 10],
})
guesses = model.predict(two_homes)
print("1 garage space:", round(guesses[0]))
print("2 garage spaces:", round(guesses[1]))
print("Difference:", round(guesses[1] - guesses[0]))
```

```text
1 garage space: 320024
2 garage spaces: 327909
Difference: 7885
```

The difference is the garage's coefficient, exactly. A model with several features is called *multiple linear regression* in a statistics class.

## A big number isn't an important feature

The garage's 7,885 is far bigger than the size's 135.57, but that says nothing about which matters more. Each coefficient is in its own feature's units: dollars per garage space, dollars per square foot. Homes differ by a few hundred square feet, but by only a garage space or so. One way to compare is to multiply each coefficient by its feature's standard deviation (the typical distance from the average, from *The Middle and the Spread*): the change in the guess for a typical difference in that feature.

```python
spread = train[features].std()
print("Typical spread:")
print(spread.round(1))
print("Coefficient times spread:")
print((spread * model.coef_).round())
```

```text
Typical spread:
size_sqft        455.5
garage_spaces      0.8
age_years         17.5
dtype: float64
Coefficient times spread:
size_sqft        61759.0
garage_spaces     6685.0
age_years       -14403.0
dtype: float64
```

A typical difference in size moves the guess about $61,759; in age, about $14,403; in garages, about $6,685. Size matters most here, though its coefficient is the smallest number of the three. *Reading Coefficients and Trees* goes further into what a model leans on.

## Features that move together share the credit

Bigger homes have more bedrooms: on the training homes, size and bedrooms have a correlation of 0.74 (*How Two Columns Move Together* explains r). Watch what happens to the bedrooms' coefficient with and without size:

```python
for columns in [["bedrooms"], ["size_sqft", "bedrooms"]]:
    trial = LinearRegression()
    trial.fit(train[columns], train["sale_price"])
    print("Features:", columns)
    for feature, coef in zip(columns, trial.coef_):
        print("   ", feature, round(coef, 2))
```

```text
Features: ['bedrooms']
    bedrooms 51386.57
Features: ['size_sqft', 'bedrooms']
    size_sqft 140.31
    bedrooms -1753.59
```

Alone, each bedroom seems worth $51,387. Next to size, it's worth −$1,754, as if a bedroom lowered the price. Neither is the "true" value of a bedroom. Alone, bedrooms took the credit that belongs to size, because they move with it; together, the model splits the credit between them, and with features this tangled, the split can swing with a little noise. In this made-up town the seed script gave bedrooms no effect of their own at all. When features move together like this, statisticians call it **multicollinearity**, and it's a reason never to read one coefficient on its own.

And none of these numbers says what *causes* a price. The model learned what went with what in these 400 sales; it doesn't know why, and correlation is not causation.

## Check yourself

2 questions to try on the lesson page.

## So what

Several features make better guesses, but each coefficient has to be read with care: in its own units, with the other features held the same, and never as a cause or as importance on its own.

## Sources

- scikit-learn 1.9.1, [LinearRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html), API reference: `coef_` holds one coefficient per feature, in the order of `X`'s columns.
- scikit-learn, [Linear Models: Ordinary Least Squares](https://scikit-learn.org/stable/modules/linear_model.html#ordinary-least-squares), User Guide: the coefficient estimates rely on the features being independent; when features are correlated, the estimates become highly sensitive to random errors (multicollinearity).
- scikit-learn, [Common pitfalls in the interpretation of coefficients of linear models](https://scikit-learn.org/stable/auto_examples/inspection/plot_linear_model_coefficient_interpretation.html), example: a coefficient is the relationship with the target while the other features remain constant; coefficients of features in different units can't be compared by size, and multiplying each by its feature's standard deviation puts them in the same unit; correlated features are hard to tease apart; and coefficients measure association, not causation.
- scikit-learn 1.9.1, [train_test_split](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html), API reference: it splits each array or table it is given into a training part and a test part.

## Key terms

- [Feature](https://www.ask-codey.com/glossary/feature)
- [Coefficient](https://www.ask-codey.com/glossary/coefficient)
- [Multicollinearity](https://www.ask-codey.com/glossary/multicollinearity)

## Related

- [Your First scikit-learn Model: fit and predict](https://www.ask-codey.com/lessons/ml-fit-and-predict)
- [Splitting Data with train_test_split](https://www.ask-codey.com/lessons/ml-train-test-split)
- [Exercise: Home Price Guesser](https://www.ask-codey.com/lessons/exercise-ml-home-price-guesser)

Source: https://www.ask-codey.com/lessons/ml-several-features
