Make the evidence travelLesson 27 of 30 · 7 min

A straight line can be confidently wrong

Diagnose a systematic model error using residuals and held-out conditions.

A fitted model estimates a relationship from data. A residual is an observed value minus its fitted prediction. A straight line can capture an overall increase while missing curvature that matters for decisions.

The invented response below grows quadratically with input size. Fit a line, then plot residuals against input. Their systematic shape reveals a missing pattern. A large correlation or a small slope p-value would not make a straight line adequate.

Model revision should lead to a test on fresh data or held-out conditions. Extrapolation means predicting beyond the tested input range; it is especially vulnerable to a wrong relationship. Include uncertainty, inspect assumptions and compare predictions with actual observations where the decision will be made.

Fit the shape, not just the slope
02.557.510-3037.5105172240Time (ms)Input size
02.557.510-3037.5105172240Time (ms)Input size
  • Authored quadratic response
  • Fitted straight line
The authored response is quadratic. The fitted line follows the overall rise while missing curvature. The residual plot in the experiment exposes the remaining pattern; a fitted slope alone cannot establish model adequacy.

Where will a straight-line fit struggle with a curved relationship?

Write a prediction (optional)

Run the prepared example

This page puts the example in the Python editor. Select Run Python with the code unchanged.

Authored model

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

What to compare

Find Residuals (ms) and follow their signs from the smallest to largest size. What does a repeatable change from positive to negative and back say about the straight-line fit?

Published example output

The site ran the original code to produce this reference. Build environment ↗

Slope (ms per size unit): 22.0
Residuals (ms): [ 24.   8.  -4. -12. -16. -16. -12.  -4.   8.  24.]
Prediction at size 10 (ms): 196.0
Authored time at size 10 (ms): 220
Residuals are positive at both ends of the size range and negative in the middle for the fitted line.
Open full-size figure ↗

The straight line captures the increase but leaves curved residuals. The model can fit the overall direction and still miss the response at sizes that matter.

Change and run again

In the Python editor, change fit_count = 10 to fit_count = 5. Select Run Python again. Compare Prediction at size 10 (ms) with Authored time at size 10 (ms). Did fitting the smaller sizes improve the prediction at a size it has not seen? Return to the Python editor

What this example supports. This deterministic quadratic example has no measurement noise. Real residual diagnostics need enough data and do not identify a unique causal mechanism.

Try a fresh case

A linear fit has a nonzero slope but curved residuals. What is the useful next step?

Choose an answer

Hints for this question
  1. Name the question answered by the slope test.
  2. Ask whether that question checks the shape of the relationship.
Your notes