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.
- Authored quadratic response
- Fitted straight line
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
A saved draft is open. To run the published example, open Editor tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
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?
Your result
Result tools
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.
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
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?
Hints for this question
- Name the question answered by the slope test.
- Ask whether that question checks the shape of the relationship.