Before a model can be trusted, it must be tested on data it has not seen during training. The train-test split is the simplest way to do this.
What the split does
You divide your dataset into two parts. The training set is used to fit the model. The test set is kept aside, and used only to check how well the model works on new data.
Why it matters
A model that scores well on the data it learned from may simply have memorised it. A test set shows whether it learned a pattern that holds for new data.
A common split
Many beginners use about 80% for training and 20% for testing. The right split depends on how much data you have. With very little data, use cross-validation instead, which repeats the split several times.
Mistakes to avoid
- Shuffling time-ordered data, so the model sees the future during training.
- Tuning the model again and again on the test set until the score looks good.
- Forgetting to fix a random seed, so your results cannot be repeated.
Next step: see our data science course at ScholarLogic, or book a free demo class. A counsellor will share the fee and the next batch dates.
