What is a residual, and what can a residual plot tell you?
A residual is actual minus predicted. Plotting residuals against fitted values should look like random scatter around zero; curves, fans or clusters reveal non-linearity, changing variance or missing variables.
Explain it simply
Every prediction misses the truth by some amount. That miss is the residual: residual = actual - predicted. Positive means the model predicted too low.
If the model captured the pattern, the leftover misses should look like noise: no shape. Any pattern in the residuals is signal the model failed to use.
Example
From the study-hours line, predicted marks are 41, 48.5, 56, 63.5, 71 and actual marks are 40, 50, 55, 65, 70.
import numpy as np
actual = np.array([40, 50, 55, 65, 70])
pred = np.array([41, 48.5, 56, 63.5, 71])
print((actual - pred).tolist()) # [-1.0, 1.5, -1.0, 1.5, -1.0]The residuals are small and flip sign, so there is no pattern here.
What shapes mean:
- U or hump shape: relationship is curved; add a polynomial term or transform.
- Funnel (fan): variance grows with the prediction; try a log transform.
- Obvious trend over time: errors are correlated; a time series approach is needed.
- One huge residual: possible outlier or data error; investigate it.
What to say in the interview
"Residual is observed minus fitted. I plot residuals against fitted values to check linearity and constant variance, and a Q-Q plot for normality. Structure in the residuals means the model is missing something, so I improve the features or the model form."
Common mistakes
- Looking only at R-squared and never plotting the residuals.