What do the slope and intercept mean in a simple linear regression?
The slope is the average change in y for a one-unit increase in x, and the intercept is the predicted y when x is zero. Least squares picks the line that minimises the sum of squared vertical errors.
Explain it simply
Regression draws the best straight line through a cloud of points: y = intercept + slope x x.
The intercept is where the line crosses the y-axis, the baseline when x is 0. The slope tells you how much y moves for each extra unit of x. The line is "best" in the least-squares sense: it makes the total of squared gaps between the points and the line as small as possible.
Example
Hours studied (x) and marks (y) for 5 students: x = 1, 2, 3, 4, 5 and y = 40, 50, 55, 65, 70.
- Mean x = 3, mean y = 56
- Slope = sum of (x - 3)(y - 56) / sum of (x - 3)^2 = 75 / 10 = 7.5
- Intercept = 56 - 7.5 x 3 = 33.5
So marks = 33.5 + 7.5 x hours. Each extra hour is linked with about 7.5 more marks. A student who studies 6 hours is predicted to score 78.5.
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([40, 50, 55, 65, 70])
slope, intercept = np.polyfit(x, y, 1)
print(round(slope, 1), round(intercept, 1)) # 7.5 33.5What to say in the interview
"The slope is the expected change in the target per unit change in the feature, holding other features constant in multiple regression. The intercept is the prediction when all features are zero, which may not be meaningful. I should not predict far outside the range of the data."
Common mistakes
- Reading the slope as proof of cause.
- Interpreting the intercept literally when x = 0 is outside the data.