Linear regression & loss
Drag points and fit a line. Watch MSE and MAE react to every outlier.
Drag points and fit a line. Watch MSE and MAE react to every outlier.
Each dot is one measurement of two quantities, x and y (for example, a plant’s age and its height). We want a straight line that predicts y from x. No line passes through every dot, so we need one number that says how badly a line misses them all: theloss.
The question: which line misses least, and how much does one odd dot (an outlier) pull it? Drag the dots to find out.
Tap empty space to add a point (8/16).
Linear regression finds the line y = mx + c that is “closest” to the data. Each red segment is a residual: how far the line misses a point. A loss function squashes all the residuals into one number.
Least squares picks the line with the smallest mean squared error. Squaring punishes big misses heavily, so a single outlier can drag the line towards it — the mean absolute error is far more relaxed.
Linear regression finds the line y = mx + c that is “closest” to the data. Each red segment is a residual: how far the line misses a point. A loss function squashes all the residuals into one number.
Least squares picks the line with the smallest mean squared error. Squaring punishes big misses heavily, so a single outlier can drag the line towards it — the mean absolute error is far more relaxed.
Things to try