Training and validation 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold
The black dots are eight training days, the blue dots three validation days. The model learns from the training days and is checked on the validation days. The model is a polynomial; its degree sets how flexible it is.
Too simple: degree 0 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold A degree 0 polynomial is a flat line, in yellow: the same prediction for every day. Training loss 109.61, validation loss 90.93. The model cannot see the effect of temperature at all; this is called underfitting.
Degree 1: a line 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold A degree 1 polynomial is a line, in red. Training loss 4.31, validation loss 0.87.
Too flexible: degree 7 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold The degree 7 polynomial, in black, bends to get as close as possible to the eight training days: training loss 0.00. The validation loss is 20.63. If the training loss falls while the validation loss rises, the model has memorised the days.
Two losses, two directions 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold As the degree grows, the training loss falls or stays the same, because the curve is more flexible. The validation loss first falls and then may rise. The number that matters is the validation loss.
The degree you chose 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold Your degree is 2: training loss 4.26, validation loss 1.12. Change the degree in the Try tab or drag the dots.
Choosing the degree 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold Among all degrees from 0 to 7, degree 1 has the smallest validation loss, 0.87. This is how model complexity is chosen; the test data is looked at only at the very end.
Why it matters 0 5 10 15 20 25 30 35 0 10 20 30 40 50 60 70 temperature, degrees ice creams sold Every model deals with this balance: too simple misses the patterns, too flexible learns the noise. More data, regularisation, dropout and early stopping are the ways used against overfitting.