Given a scatter of points, what's the single "best" line through them — and what does "best" even mean here?
Drag either end of the line. The dashed segments are each point's residual — how far it misses the line, straight up or down. A good fit is one where those misses are all small at once.
Squaring each residual before adding them up gives the standard measure of fit — the sum of squared errors (SSE):
- SSE — the sum of squared errors: how far the line's predictions miss the actual data, added up.
- — the actual (observed) value for data point .
- — the line's slope.
- — the input value for data point .
- — the line's intercept.
- Every term becomes positive
Squaring means misses in opposite directions can't cancel out — a point the line overshoots and a point it undershoots both add to the total instead of offsetting each other.
- One large miss costs far more than several small ones
Squaring also makes a big residual disproportionately expensive, so a line has to stay close to every point, not just close on average.
Drag toward a better angle and watch , , and the SSE update together — the line's slope and intercept are just two numbers, and SSE is one number summarizing how well those two numbers fit everything at once.
With :
- Compute the predictions
at each :
- :
- :
- :
- :
- :
Against actual values .
- Compute the residuals
at each point:
- Square and sum them
Close, clean numbers — and already a good fit, without needing the exact optimum.
Drag either end of the line until the total squared error, SSE, drops below 2.0.
Fitting a line means choosing and to make this sum as small as possible. Next: what changes if you measure "small" a different way.