Multiple Features
Predicting a house's price from its size alone throws away obviously relevant
information: two houses of the same size can sell for very different prices if one has more
bedrooms, is much older, or sits in a different neighbourhood. Real predictions almost always draw
on many features at once.
The
hypothesis function you already know,
h(x) = wx + b, is really just the special case of a single feature. Give
every feature its own weight and add them all up, and the very same idea — a straight-line rule
through the data — becomes a straight hyperplane through many features simultaneously:
h(\vec{x}) = w_1 x_1 + w_2 x_2 + \dots + w_n x_n + b.
Set n=1 and this collapses right back to
h(x) = w_1 x_1 + b — the one-feature model you started with. Nothing
about the underlying idea changed; there are simply more terms in the sum.
One clean line: the dot product
That sum of weight-times-feature is exactly a
dot product of the
weight vector \vec{w} = (w_1, \dots, w_n) with the feature vector
\vec{x} = (x_1, \dots, x_n). So no matter how many features a model has —
three or three hundred — the whole prediction collapses to one clean expression:
- Expanded form: h(\vec{x}) = w_1 x_1 + w_2 x_2 + \dots + w_n x_n + b
- Vector form: h(\vec{x}) = \vec{w}\cdot\vec{x} + b, a single dot
product plus the bias.
Here is linear algebra paying off directly: "weight each feature and add them up" is literally
what a dot product computes, so the model that looks intimidating with a hundred features is
exactly as simple to write down as the one with a single feature.
Worked example: predicting one house's price
Suppose training has already found the weights
w_1 = 150 (per square foot), w_2 = 8{,}000
(per bedroom), w_3 = -900 (per year of age), and bias
b = 20{,}000. A specific house has
x_1 = 1{,}800 sq ft, x_2 = 3 bedrooms, and
x_3 = 15 years old. Plug straight into the formula:
h(x) = w1·x1 + w2·x2 + w3·x3 + b
= (150)(1800) + (8000)(3) + (-900)(15) + 20000
= 270000 + 24000 - 13500 + 20000
= 300500
The model predicts \$300{,}500 for this house — one number, produced by
weighing up size, bedrooms, and age all at once.
Reading the weights themselves
Once training is done, the weights aren't just numbers to plug in — each one tells a small story
about that feature, holding everything else fixed:
-
w_1 = 150 > 0 on size: a positive weight
means bigger houses are predicted to cost more — every extra square foot adds
$150 to the prediction.
-
w_3 = -900 < 0 on age: a negative weight
means older houses are predicted to cost less — every extra year of age subtracts $900,
all else being equal.
-
A weight close to 0 would say that feature barely moves the
prediction either way, regardless of its value.
Play with the dials below: the feature values for one fixed house stay put while you adjust the
weights, so you can see exactly how each weight's sign and size push the prediction up or down.
Worked example: does the extra feature actually help?
Compare two models trained on the same houses. A single-feature model uses only
size: h(x) = 140x + 30{,}000. A house that is
1{,}200 sq ft but unusually new and in a great school catchment area
might sell for \$225{,}000 — well above the single-feature model's guess
of 140(1200) + 30000 = \$198{,}000. A
multi-feature model that also sees "age" and "school rating" can pick up exactly
that extra pattern and push its prediction much closer to the true price, because it has been
given the information that explains the gap. Adding a genuinely predictive feature doesn't
change the algorithm — it just gives it more of the picture to work with.
From a line to a hyperplane
Picture it geometrically and the jump from one feature to many is just adding dimensions. With a
single feature, h(x) = w_1 x_1 + b traces a straight line
through a 2-D scatter plot (feature on one axis, price on the other). Add a second feature and
h(x) = w_1 x_1 + w_2 x_2 + b traces a flat plane tilted
through 3-D space — one tilt for size, a different tilt for bedrooms, both baked into a single flat
sheet of predictions. Keep adding features and the surface becomes a hyperplane: the
same idea, just living in more dimensions than we can draw. You can't sketch a 10-dimensional
hyperplane, but the algebra — one weight per axis, summed with the dot product — works exactly the
same whether there are 2 features or 200.
See the plane: two features, one tilted sheet
With two input features, linear regression fits a plane through the
data cloud — not a line. Each point below is a training example: its two horizontal coordinates are
the features x_1 and x_2, and its
height is the target y. The tilted sheet slicing through them is
the model's prediction h(\vec{x}) = 0.7\,x_1 + 0.5\,x_2 — one tilt for each
feature, baked into a single flat surface. Drag to rotate and watch the plane cut
right through the middle of the scatter.
Same algorithm, more knobs
Nothing else changes. The
cost
is still mean squared error, and
gradient
descent still rolls downhill — just in more dimensions, adjusting every weight at
once. Writing the model as \vec{w}\cdot\vec{x}+b is also why a whole
dataset can be processed as one big matrix–vector
multiply — fast, and exactly what hardware loves. It's also why the
normal
equation generalizes so cleanly from one feature to many: the same matrix algebra that
solves for a single slope and intercept solves for an entire vector of weights at once.
Bias: the one term every feature shares
Notice the bias b doesn't get multiplied by any feature — it's added on
its own, the same amount regardless of size, bedrooms, or age. It represents the model's baseline
prediction when every feature happens to be zero (or, more usefully, it's simply the extra shift
that makes all the weighted terms line up with the actual prices in the training data). With one
feature this was easy to picture as "where the line crosses the price axis"; with many features it
plays exactly the same role, just for a hyperplane instead of a line.
One more useful way to think of it: append a constant feature x_0 = 1 to
every example, and set its weight to w_0 = b. Then the whole hypothesis —
bias included — becomes a single dot product,
h(\vec{x}) = \vec{w}\cdot\vec{x}, with no separate +b
term left over. It's a small notational trick, but it's exactly how the maths is usually written
once matrices enter the picture.
-
Comparing weight sizes directly only makes sense once features share a scale.
An unscaled weight of 150 "per square foot" and an unscaled weight of
8{,}000 "per bedroom" are not telling you bedrooms matter roughly 53
times more than size — square feet and bedroom counts simply live on totally different scales.
Only after
feature
scaling puts every feature on comparable footing does the raw size of a weight become
a fair signal of how much that feature matters.
-
Watch out for near-duplicate features, too. Include both "size in square feet"
and "size in square metres" as separate inputs and the model can no longer tell which one
"deserves" the credit for size's effect — it can split the weight between them almost arbitrarily,
or swing it wildly with tiny changes in the data. This instability from two (or more)
highly-correlated features is called multicollinearity; the fix is usually to
drop the redundant feature rather than feed the model the same information twice. Concretely: if
x_{\text{sqft}} \approx 10.76\, x_{\text{sqm}} for every house in the
data (they measure the very same thing), then any pair of weights satisfying
w_{\text{sqft}} + 10.76\,w_{\text{sqm}} = \text{target} fits the
training data equally well — training could hand back wildly different-looking weight pairs
depending on tiny nudges in the data, even though the model's actual predictions barely change.
Zoom forward to neural networks and you'll meet this exact structure again wearing a different
name: a single artificial neuron takes a handful of inputs, multiplies each one by
its own weight, adds a bias, and outputs the result — precisely
\vec{w}\cdot\vec{x}+b. Stack enough of these neurons in layers (each
typically followed by a small nonlinear twist) and you get a neural network. In a very real sense,
multiple linear regression is a single neuron, and you've already learned the core
computation that every larger network is built from.
Well-known online home-value estimators don't stop at three features. They fold in dozens to
hundreds of signals at once — square footage, bedroom and bathroom counts, lot size, age,
renovation history, school ratings, recent nearby sale prices, walkability, and more — each with
its own learned weight, all summed (often with extra machinery layered on top) into one estimated
price. The three-feature toy example on this page is the exact same idea, just running at a much
smaller scale.