Least squares in this visualization
Three points rarely lie on one line, so any line misses some of them. On the left are the points, the best line and its residuals, the vertical misses whose squares add up to SSE. On the right the same three heights form one vector in space, and finding the best line means projecting that vector onto a plane. You can move the points, try a line of your own and compare two simpler models.
Why is the data a single point? Write the three heights as one vector . That is the blue arrow on the right, and its axes are named because each one measures a height. A line takes the values at the three , which is the vector with . In the general model , with the not all equal, these vectors fill the glass plane through and as and vary. So every line you could draw on the left is one point of that plane.
Pick any line. Its residuals are the coordinates of minus those of its point in the plane, so its SSE is the squared distance between the two. The best line therefore sits at the point of the plane nearest to , the orthogonal projection. The residual vector meets the plane at a right angle, so it is perpendicular to both and . Written out, the two right angles are the normal equations:
With Right angles and balance on, the residuals become equally stiff vertical springs. Their net force is proportional to , and their torque about the origin to . The general fit makes both zero. The constant model needs only the net force to vanish, and the line through the origin only the torque.
Your line, drawn in red, is always a line of the current model, so its point lies in the same plane or line as . The step from to lies there too, while is perpendicular to it, so Pythagoras splits your error exactly. Your SSE reaches the minimum exactly when .
The two smaller models keep one column each. Fitting projects onto the line through , and comes out as the mean of the heights. Fitting projects onto the line through , or just onto the origin when every is 0. When the are not all equal, these are two different lines in the plane. Neither model contains the other, and the general line does at least as well as both. The same projection is at the heart of linear regression.
Things to notice
- The residuals are vertical. Least squares measures the miss in at each , not the shortest distance from a point to the line.
- In the general model, when all three are equal, the plane shrinks to the line through . Every line through the hollow ring fits equally well, so the best line is not unique, although still is.
- Parameter plane shows the general model's SSE as a function of and . Each data point gives a line of pairs that fit it exactly, and blue marks the current model's best parameters.
Controls
- The right picture only turns and zooms. Drag the points up and down on the left, and type an in the panel to move a point sideways.