Curvingo · Made in India

Glossary

Select one of the keywords on the left…

Linear RegressionModel Evaluation

Reading time: ~10 min

To say that one line is better than another, we need a score. In machine learning, a number that measures how wrong a model is, is called a loss. During training, what should the model do with its loss?

Make it as small as possible
Make it as large as possible
Ignore it

Exactly — training means minimising the loss. The question is which loss to use.

Mean Squared Error

Here are four of Riya's days with the predictions of \hat{y} = 6x - 100.

Temperature xSold yPredicted \hat{y}Error y - \hat{y}Error squared
245244864
307480−6
3497104−749
40148140864

Why not just add the errors? 8 - 6 - 7 + 8 = 3, which looks tiny — yet the line misses every day by 6 to 8 kulfis. Positive and negative errors . Squaring makes every error positive, and it punishes big misses much more than small ones: an error of 8 counts as 64, an error of 2 only as 4.

The mean of the squared errors is (64 + 36 + 49 + 64) \div 4 = .

Mean squared error

For n data points,

\text{MSE} = \dfrac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2

where y_i is the real value and \hat{y}_i is the model's prediction for point i.

Seeing the Squares

Here each error is drawn as a real red square — the MSE is their average area. The second score, R² ("R-squared"), compares your line with the lazy average line: R² = 1 is a perfect fit, R² = 0 is no better than always guessing 86, and below 0 is worse than that. Drag the knobs and complete both missions.

R-Squared

R² answers the question "how much better than the lazy guess is my line?"

R^2 = 1 - \dfrac{\text{MSE of your line}}{\text{MSE of the lazy average}}

For Riya, the lazy average has an MSE of 822.8 and the best line has an MSE of 30.8. So R^2 = 1 - 30.8 \div 822.8 \approx .

In words: the line explains about 96 % of the ups and downs in Riya's sales; the other 4 % is noise. A model that simply predicts the average every time has an R² of exactly .

Tip

There is no single best score. MSE punishes big misses hard, but it is measured in "kulfis squared". The mean absolute error (MAE) averages the sizes of the errors without squaring — for the table above, (8 + 6 + 7 + 8) \div 4 = 7.25 kulfis — which is easier to explain to Riya. Pick the score that matches what you care about.

Sina