Total Squared Error
Introduction
Welcome back to Fitting a Line to Data! You have made it to the fourth of five lessons in this course, which means you are well on your way to mastering how a best-fit line works. So far, we have assigned explanatory and response roles, summarized a trend with a straight line, and learned how to compute residuals for individual data points. Each residual gave us an exact number for one point's gap from the line.
But here is the challenge: a single data set can produce many residuals, and simply looking at a long list of them does not tell us much at a glance. In this lesson, we will learn how to combine all of a line's residuals into one score that captures overall fit. That score will let us compare two competing lines and say, objectively, which one does a better job.
From Many Residuals to One Score
In the previous lesson, you learned that a residual is the vertical gap between an observed value and the predicted value on the line (). When we fit a line through a scatter plot with ten points, we get ten residuals. With a hundred points, we get a hundred.
Staring at a list of residuals and trying to judge overall fit is almost as subjective as eyeballing the plot itself. What we need is a way to collapse that entire list into a single number so that comparing two lines becomes as simple as comparing two numbers: the smaller number wins.
The Problem with Simply Adding Residuals
The most natural first idea is to add up all the residuals. If a line fits well, every residual should be small, so their sum should be small too, right? Let's test that intuition with a quick example.
Suppose a line produces these four residuals: , , , . Adding them gives:
A sum of zero looks perfect, yet the line misses every single point by 2 or 3 units! The positive and negative residuals cancel each other out, masking the real error. In fact, any reasonably balanced line will have positives and negatives that largely cancel. So the plain sum of residuals is nearly useless as a measure of fit.
Square Each Residual, Then Add
To stop positive and negative residuals from canceling, we square each residual before adding. Squaring does two useful things at once:
- It makes every value positive, so nothing cancels out.
- It magnifies large gaps more than small ones. A residual of contributes , while a residual of contributes just .
The result is called the total squared error (also known as the sum of squared residuals):
The rule for reading this score is simple: a smaller total squared error means a better fit.

