A residual plot displays fitted values against residuals to reveal systematic error patterns that a goodness-of-fit measure such as R² may miss. For a suitable linear model, residuals should appear randomly scattered around a horizontal zero line; curves, funnels, or other trends indicate unexplained structure. section 4.2.4 section 7.3.10
>>> plt.scatter(lm.fittedvalues, lm.resid) #1
>>> plt.axhline(y = 0, color = 'red',
>>> linestyle = '--') #2
>>> plt.title('Residuals Plot') #3
>>> plt.xlabel('Fitted Values') #4
>>> plt.ylabel('Residuals') #5
>>> plt.show() #6
Create the diagnostic with fitted values on the x-axis, residuals on the y-axis, and a dashed reference line at zero. section 4.2.4
Interpret the visual pattern before relying on additional diagnostics:
- Random scatter around zero supports the linearity assumption and suggests that the model captured the systematic linear component. section 4.2.4
- Curves or funnel shapes suggest that a linear model is insufficient or that error variance is not constant. section 4.2.4 section 7.3.10
- For time-series models, combine the residual plot with density, ACF, and PACF diagnostics to assess normality, independence, and white-noise behavior. section 7.3.10


