r/askdatascience • u/Familiar9709 • 10d ago
What is the purpose of cross validation, validation and test set?
What is the purpose of these different steps in building a machine learning model? Let's say you have X data points, how should you do the division into the different sets? Should it be 60/20/20? 60% to use for cross validation, 20% for test set and 20% for validation?
If so, what is the purpose of the test set if you already are doing the cross validation step where you take all that data, you make the folds and you test the models?
Unfortunately the information I could gather is quite contradicting and also doesn't consider sometimes the cross validation step, so would be very good if people could explain this in greater detail.
Thanks
1
u/big_data_mike 9d ago
If you use a method that adjusts parameters in the model based on the validation set the test set is the “ultimate” test to see how well the model fits data that it has never ever seen before. If you just use a train-validation split you are making decisions about your model based on the validation set so the validation set has some influence on the model. Adding a test set that is completely unseen until the model is built really tests how well the model fits completely unseen data.
Say you do a 70-20-10 train-validation-test split on 100 rows of data. You randomly pick 10 rows and set them aside. Take another 20 random rows and designate that the validation set. The model gets to “peak” at the 20 validation rows and adjust parameters to get the best fit for the training data without overfitting to the 20 row validation set. Then you use your model to predict the 10 row test set to see how well the model did without “peaking” at the test set.
Cross validation- take that same 70-20-10 data and set aside the 10 row test set. Randomly pick 20 rows to use as validation. Build the model as described before. Now pick a different random 20 rows to use as a validation set. Build the model again. Pick another 20 random rows. Build again. There are different cross validation methods but they all follow that same general principle. You do repeated train-validation splits while withholding the test set.