liveBook · Manning

Residual plot

As explained in Statistics Every Programmer Needs

A residual plot is a graph displaying model residuals against fitted values or another explanatory quantity to reveal systematic error patterns.

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

How Statistics Every Programmer Needs covers it

How deep it goes
Explains construction and visual interpretation, then connects patterns to linearity, variance, independence, and normality diagnostics.
Examples
Uses Matplotlib scatter plots, zero reference lines, residual-density plots, and ARIMA residual diagnostics as concrete examples.
What it assumes
Assumes a fitted regression or time-series model with observed values, predictions, fitted values, and residuals available.
What you can do after
Diagnose model assumptions by plotting residuals and identifying randomness, trends, curves, funnels, or remaining time-series correlation.
How it connects
Connects residual plots with linear regression, fitted values, heteroskedasticity, autocorrelation, normality, ARIMA, ACF, and PACF.

Also explained in

Compare how 3 books explain residual plot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.