Linear RegressionModel Evaluation
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?
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 .
| Temperature | Sold | Predicted | Error | Error squared |
|---|---|---|---|---|
| 24 | 52 | 44 | 8 | 64 |
| 30 | 74 | 80 | −6 | |
| 34 | 97 | 104 | −7 | 49 |
| 40 | 148 | 140 | 8 | 64 |
Why not just add the errors? , which looks tiny — yet the line misses every day by 6 to 8 kulfis. Positive and negative errors
The mean of the squared errors is
Mean squared error
For data points,
where is the real value and is the model's prediction for point .
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?"
For Riya, the lazy average has an MSE of 822.8 and the best line has an MSE of 30.8. So
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, kulfis — which is easier to explain to Riya. Pick the score that matches what you care about.