Linear Regression as a Model
The same affine computation can predict a continuous quantity.
Suppose x is the number of hours a machine has run and y_hat is its predicted
energy use:
y_hat = wx + b
Here the output is a prediction, not a class score. If w = 1.5 and b = 2, then
for x = 4:
y_hat = 1.5 * 4 + 2 = 8
This is linear regression with one feature. The weight says that each additional
hour changes the prediction by 1.5 units. The bias is the prediction at x = 0.
Whether that intercept has a sensible real-world interpretation depends on whether
zero hours is meaningful and represented by the data.
Several Features Use the Same Rule
For a feature vector x and weight vector w:
y_hat = x · w + b
Let:
x = [3, 2]
w = [4, -1]
b = 5
Then:
y_hat = 3 * 4 + 2 * (-1) + 5
= 12 - 2 + 5
= 15
The arithmetic is the affine map from the previous lesson. “Regression” names the task: predicting a numerical target. Training still needs a dataset and a loss; this page only defines the model's prediction.
Inspect a linear-regression prediction
Change a feature or weight and inspect each contribution before the final prediction.
Ready to run.
A linear-regression model is y_hat = 2.5x - 1. What does it predict for
x = 4?
Compute it first, then check your number.
HintSubstitute the input
Compute 2.5 * 4 - 1.
SolutionApply the affine rule
The prediction is 2.5 * 4 - 1 = 10 - 1 = 9.
In y_hat = 2.5x - 1, how much does the prediction change when x increases by
one unit?
Compute it first, then check your number.
HintRead the slope
The coefficient multiplying x is the change per input unit.
SolutionThe weight is the slope
The weight is 2.5, so increasing x by one increases the prediction by 2.5
when everything else stays fixed.