What are the assumptions of linear regression?
The main ones are a linear relationship, independent errors, constant error variance (homoscedasticity), roughly normal errors for inference, and no severe multicollinearity. Violations mainly hurt interpretation and confidence intervals rather than raw prediction.
Explain it simply
Linear regression works best when the data behaves in a particular way. A helpful acronym is LINE:
- Linearity: y relates to x along a straight line (or you have transformed things so it does).
- Independence: one row's error does not tell you another row's error. Time series data often breaks this.
- Normality: errors are roughly bell-shaped. This matters for p-values and intervals, much less for the fitted line.
- Equal variance: the spread of errors is the same across the range of predictions.
Add one for multiple regression: predictors should not be nearly copies of each other.
Example
Predicting house price from area. A residual plot (errors against predictions) shows a fan: small errors for cheap flats, huge ones for expensive flats. Equal variance is violated.
Typical fixes:
- Take the log of price, which often evens out the fan.
- Add a squared term if the plot curves.
- Use robust standard errors.
import numpy as np
resid = np.array([-1, 1.5, -1, 1.5, -1])
print(round(resid.mean(), 2)) # 0.0Residuals from least squares with an intercept average to zero over the full fitted data; check patterns, not the mean.
What to say in the interview
"I check linearity and equal variance with a residual plot, normality with a Q-Q plot of the residuals, independence from how the data was collected, and multicollinearity with VIF. Prediction survives many violations, but inference such as p-values and confidence intervals does not."
Common mistakes
- Thinking the features or the target themselves must be normal. It is the errors that matter.