Algorithms Made Simple · 5 min read
A model that scores perfectly on the data it studied has told you almost nothing. You need to test it on data it has never seen.
The idea
Split your data into a training set, used to fit the model, and a test set, kept aside until the end. The test score estimates how the model will do on new cases. A common split is around 80% for training and 20% for testing.
Overfitting
An overfit model memorizes quirks of the training data. You will see high training accuracy and noticeably lower test accuracy, say 98% versus 70%. A gap like that is the warning sign. Simpler models, more data and regularization can all reduce it.
A third set for choices
If you try many settings and pick the one with the best test score, you have quietly tuned to the test set. Use a separate validation set to compare options, and touch the test set only once. Cross-validation, which rotates which part is held out, makes better use of small datasets.
Mistakes to avoid
- Leakage: information from the answer sneaking into the inputs, or the same customer appearing in both sets.
- Splitting time-ordered data randomly. Train on the past and test on the future.
- Trusting accuracy when classes are imbalanced. If 99% of emails are not spam, a model that always says “not spam” scores 99%. Look at precision and recall as well.
- Skipping a simple baseline to compare against.
