Why does the best-fitting line minimize squared errors?
You will be able to: Explain least squares and compare candidate lines using squared residuals.
Why does the best-fitting line minimize squared errors?
Two lines can both pass near a class’s quiz scores. We need a consistent rule for deciding which line predicts these data with less error.
A useful starting point: How can errors reveal that a line is the wrong shape? →
Words and symbols before equations
- Squared residual e²
- The residual multiplied by itself, so positive and negative errors both contribute nonnegative amounts.
- SSE
- Sum of squared residuals across all observed pairs.
- Least-squares regression line
- The line with the smallest SSE among all candidate intercepts and slopes.
- Parameter surface
- A plot showing how SSE changes as the candidate intercept and slope change.
What this picture assumes
Fixed synthetic data: (1,5),(2,4),(3,10),(4,8),(5,13), in hours and points. The best fit is intercept 2 and slope 2 with SSE=14 points squared. The 3D height is SSE, not a third measured variable. Axes stay fixed: intercept 0–4, slope 1–3, SSE 0–160. No motion runs automatically.
Read the picture in three steps
- Read the axes and labels first. Identify what each symbol and line represents. Read the units and fixed conditions before comparing quantities.
- Candidate ŷ=2 + (2)x; SSE=14 points². Best: ŷ=2+2x, SSE=14. Excess squared error=0 points². Dashed segments are vertical residuals.
- Check what the picture assumes below. Use the Explore task to predict one change before moving a control.
Connect the picture to the mathematics
Adding signed errors can hide poor predictions because positive and negative errors cancel. Squaring prevents cancellation and gives larger errors a greater contribution. SSE has squared response units; it is not an average error in points.
For the five pairs (1,5),(2,4),(3,10),(4,8),(5,13), the least-squares line is ŷ=2+2x. Its residuals are 1,−2,2,−2,1 and SSE=1+4+4+4+1=14 points squared.
The candidate line ŷ=1+2x has residuals 2,−1,3,−1,2 and SSE=19. Moving both intercept and slope changes the fit. The optional 3D surface uses these two parameters as horizontal directions and SSE as height, making the minimum visible. It is a parameter landscape, not a scatterplot of three measured variables.
A worked example, step by step
Compare ŷ=2+2x with ŷ=1+2x on the five stated pairs.
- Calculate predictions for the first line: 4,6,8,10,12.
- Subtract to get residuals 1,−2,2,−2,1; square and sum to obtain 14.
- For the second line predictions are 3,5,7,9,11, giving residuals 2,−1,3,−1,2 and SSE=19.
- The first has smaller SSE; technology confirms it is the global least-squares fit for these data.
Least squares minimizes squared vertical residuals, not the signed sum or perpendicular distances.
Why not minimize the sum of signed residuals?
Compare with an explanation
Large positive and negative errors could cancel even when predictions are poor.
Predict. Change one thing. Explain.
Start with intercept 2 and slope 2. Change one at a time, then both. Compare SSE with the best fit and inspect the optional 3D minimum; camera rotation must not change the numbers.
On narrow screens, swipe or scroll diagrams sideways to read all labels.
Candidate ŷ=2 + (2)x; SSE=14 points². Best: ŷ=2+2x, SSE=14. Excess squared error=0 points². Dashed segments are vertical residuals.
| Student | x (hours) | y (points) | ŷ (points) | e=y−ŷ (points) | e² (points²) |
|---|---|---|---|---|---|
| P1 | 1 | 5 | 4 | 1 | 1 |
| P2 | 2 | 4 | 6 | -2 | 4 |
| P3 | 3 | 10 | 8 | 2 | 4 |
| P4 | 4 | 8 | 10 | -2 | 4 |
| P5 | 5 | 13 | 12 | 1 | 1 |
| Slope b (points/hour) ↓ / Intercept a (points) → | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| 1 | 149 | 104 | 69 | 44 | 29 |
| 1.5 | 77.75 | 47.75 | 27.75 | 17.75 | 17.75 |
| 2 | 34 | 19 | 14 | 19 | 34 |
| 2.5 | 17.75 | 17.75 | 27.75 | 47.75 | 77.75 |
| 3 | 29 | 44 | 69 | 104 | 149 |
Fixed synthetic data: (1,5),(2,4),(3,10),(4,8),(5,13), in hours and points. The best fit is intercept 2 and slope 2 with SSE=14 points squared. The 3D height is SSE, not a third measured variable. Axes stay fixed: intercept 0–4, slope 1–3, SSE 0–160. No motion runs automatically.
Explain what you noticed: Answer the investigation prompt above. State one observation and explain it using the paired observations, predictions, residuals, graph scales or model assumptions. Identify what the representation cannot tell you.
Apply the idea to a fresh problem Practice →Show what you understand.
Two original questions are a starting check, not proof of mastery. Explain your choice before revealing the answer.
Original written challenge
4 points · self-check · not an official AP questionOn the same three observations, line A has residuals 1,−1,2 and line B has residuals 0,0,3. Compare their SSE and explain the criterion.
This response is not submitted or saved. Copy it before leaving.
Compare with the answer and four-point rubric
- 1 point: Square each residual for A: 1,1,4.
- 1 point: A has SSE=6; B has SSE=0+0+9=9.
- 1 point: A is better by the least-squares criterion among these two candidates.
- 1 point: This does not prove A is the best among every possible line or that either model is appropriate.
Accept equivalent correct methods and explanations. This is a Refresh Kid teaching rubric, not an official AP scoring guideline.
Retrieve it before you reveal it.
RECALL 1What does least squares minimize?
The sum of squared vertical residuals.
RECALL 2Why square errors?
To avoid cancellation and penalize large errors more.
RECALL 3What is the third dimension in the surface?
SSE, not a third measured variable.
Revisit these tomorrow and a week later. Try a fresh problem and explain why the method applies.
Why does the best-fitting line minimize squared errors?
- SSE=Σ(y−ŷ)².
- Minimize SSE over a and b in ŷ=a+bx.
- SSE units are squared response units.
Remember: Least squares minimizes squared vertical residuals, not the signed sum or perpendicular distances.
Conditions: Fixed synthetic data: (1,5),(2,4),(3,10),(4,8),(5,13), in hours and points. The best fit is intercept 2 and slope 2 with SSE=14 points squared. The 3D height is SSE, not a third measured variable. Axes stay fixed: intercept 0–4, slope 1–3, SSE 0–160. No motion runs automatically.
Refresh Kid · AP Statistics Unit 5 · Objectives 5.5.A · Review edition
Framework, scope and review status
Mapped to College Board, AP Statistics CED, Topic 5.5, objectives 5.5.A. Framework effective Fall 2026, checked September 17, 2026. Unit 5 is Regression Analysis in the revised five-unit course: scatterplots, correlation, linear prediction, residuals and least squares. Inference tests for regression slopes are outside this unit.
Examples and datasets are synthetic, independently authored teaching material. Correlation describes linear association, not causation. Least squares uses squared vertical residuals and a fitted intercept. Check scatterplots, residual patterns, unusual observations, explanatory range and population applicability before interpreting a model. Five-point demonstrations do not support population or causal claims.
The Organic Chemistry Tutor companion title and destination were checked; the full video was not reviewed. Khan Academy’s destination was located, but full lesson content was not available to the research tool. OpenStax is optional reference reading. No provider scripts, questions or graphics were copied. Refresh Kid is not affiliated with these providers.
GitHub’s 3D website collection informed optional spatial inspection. Our original least-squares surface uses self-hosted Three.js with its MIT license. The two base axes are candidate intercept and slope; vertical height is the resulting sum of squared errors. Rotation helps inspect the valley and its minimum as two parameters change. This is a parameter surface, not three measured variables. Fixed scales, an exact 2D parameter table and a labeled scatterplot provide alternatives. No autoplay or external 3D dependency is required.
Independent teacher review and observation of students remain pending. Technical checks do not certify statistical accuracy, accessibility or learning effectiveness. This is a review edition.
Released AP Statistics questions and scoring guides are optional. Older exams use the earlier framework, so check alignment before selecting parts. All practice on this page is original, not official AP material.
Learn → Explore → Practice → Review is informed by the IES learning guide. This implementation has not yet been evaluated with learners.
Want to work through this with a tutor?
Bring your question about Why does the best-fitting line minimize squared errors? Your explanation and answers remain free to access.
