There are two respectable ways to estimate how a model will do on data it has not seen. One is the hold-out: set aside a slice, say 20 percent, train on the rest, score on the slice. The other is k-fold cross-validation: split the data into k parts, train k times, each time holding out a different part, and average the scores. I will argue that for the data sizes most Indian business teams actually have, cross-validation deserves to be the default, and then I will tell you where it should not be used.
What a single hold-out really gives you
Hold-out is simple, fast, and easy to explain. If you have a million rows, it is also perfectly adequate: a 20 percent slice is 2 lakh rows, and the score will barely move if you re-draw it.
The trouble starts with smaller sets. Imagine 1,500 loan applications, of which 150 defaulted. A 20 percent hold-out has 300 rows, and around 30 defaulters. Whether your model looks good or poor on those 30 people is partly luck: a few hard cases landing in the test slice can swing the score noticeably. Worse, you only learn one number, so you cannot tell how much of it is luck. Two analysts using different random seeds can report different accuracy for the same model and each be honest.
The hold-out also wastes data. The 300 rows in the test slice teach the model nothing. When data is scarce, that is a real cost.
What five folds give you
With five-fold cross-validation, every row is used for testing exactly once and for training four times. Suppose the five fold scores (say, AUC, or any metric you pick) are 0.71, 0.74, 0.69, 0.78 and 0.73. The mean is 0.73 and the standard deviation about 0.034. You now have two pieces of information: the typical performance and a sense of its wobble. If a rival model averages 0.74 with similar wobble, you should not declare it better; the gap is smaller than the noise. A single hold-out could never reveal that.
That is why cross-validation is the natural tool for choosing between models or tuning settings. The comparison happens across the same folds, and the spread tells you whether a difference is believable. Five or ten folds are the common choices. Ten reduces the bias of training on less data but costs twice the compute, and the gain from five to ten is usually modest. Leave-one-out, where k equals the number of rows, is very expensive and its estimates can themselves be unstable, so I would not reach for it unless the dataset is tiny.
Where the argument breaks
Cross-validation assumes that rows are interchangeable, and often they are not.
- Time-ordered data. Forecasting demand with random folds lets the model train on March and test on February, which is cheating on the future. Use forward-chaining: train on months 1 to 6, test on 7; train on 1 to 7, test on 8; and so on. Scikit-learn offers a time-series splitter for this.
- Grouped data. If one customer has twelve transactions and they are scattered across folds, the model learns that customer in training and is tested on the same person. Scores come out flattering. Keep every row of a group in the same fold.
- Rare outcomes. With 10 percent defaulters, a random split can leave one fold with unusually few. Stratified folds preserve the class ratio in each fold.
The other trap is preparing data before splitting. If you scale features, fill missing values or select the best variables using the whole dataset and then cross-validate, information from the test folds has already leaked in. Anything learned from data belongs inside each training fold. Pipelines in common libraries exist to make this automatic.
My position, and the one thing to keep separate
Use cross-validation while you are developing: comparing models, tuning, choosing features. Use hold-out when data is plentiful, or when training is so slow that five runs are impractical, such as a large neural network that takes a day per run.
Whichever you use during development, keep one final test set that nobody touches until the end. Cross-validation scores guided your choices, so they are slightly optimistic; you have, in effect, studied for those folds. One last, untouched slice gives a figure the choices could not have influenced. If that figure disagrees sharply with the cross-validated one, something is leaking or the data has drifted, and you should find out before the model goes live.
Fair objection: this is more work. Yes. It is also cheaper than telling the credit committee the model would catch 80 percent of defaulters and then discovering it catches 60.
Figures and names in the examples are illustrative.
Leave a Reply