Test Set in Machine Learning

A validation data is an example of data from your model’s training that is commonly used to estimate model competence while tuning the hyperparameters of the model.

The validation dataset is distinct from the test dataset, which is likewise withheld from the model’s training and is instead utilized to provide an impartial evaluation of the last adjusted model’s skill for selecting or comparing between models.

Training, validation, and test dataset

The training dataset is a set of data that was utilized to fit the model.

A validation dataset is a subset of data used to offer an objective assessment of a model’s fit on the training data while changing hyperparameters. As competence on the validation data is an integral part of the model setup, the evaluation becomes increasingly biased.

The test dataset is a subset of the training dataset that is utilized to give an objective evaluation of a final model.

There are additional methods for computing an unbiased, or increasingly biased in the context of the validation dataset, assessment of model skill on unknown data.

Using k-fold cross-validation instead of a separate validation dataset to modify model hyperparameters is a frequent example.

However, in modern applied machine learning, you are unlikely to come across references to training, validation, or test data.

If the developer chooses to change model hyperparameters with the training dataset, the reference to a “validation dataset” is removed.

Test data vs validation data

When evaluating models, there is a clear definition of what test dataset, training dataset, and validation dataset mean.

The “validation dataset” is most commonly used to describe model assessment during tuning hyperparameters and data preparation, while the test data is most commonly used to describe model assessment when comparing it to other final tuned models.

When using different resampling methods like k-fold cross-validation, the concepts of validation data and test data may vanish, especially when the resampling methods are nested.

Training set vs test set

Ensure that your test set satisfies the following two requirements:

It is big enough to produce statistically significant results and it’s reflective of the entire data collection. To put it another way, don’t choose a test set that differs from the training set.

So what is the test set in machine learning?

  • A training set is a subset of data used to train a model
  • Test set—a subset used to put the trained model to the test

Your goal is to develop a model that generalizes well to new data, assuming your test set fits the two constraints mentioned above. Our test set acts as a stand-in for new information. Let’s say that the model learned for the training data is really basic. This model isn’t perfect; a few predictions are incorrect. This model, however, performs about as well on test data as it does on training data. To put it another way, this straightforward model does not overfit the training data.

If you’re getting remarkably good results on your assessment metrics, it’s possible you’re training on the test set by accident. High accuracy, for example, could suggest that testing data in machine learning has gotten into the training set.

  • Never train on test data

Validation accuracy vs test accuracy

The distinction between validation and test sets (and their respective accuracies) is that validation sets are used to build/select a better model, whilst test sets are used to test the final model. However it isn’t used to choose between models here, its 10% held-out is a test set rather than a validation set.


Consider a model that uses the title tag, email contents, and recipient’s email address as features to predict if an email is spam. With an 80-20 split, we divide the data into training and test sets. The model achieves 99 percent precision on both the training and test sets after training.

We’d expect a lower precision on the test set, so we dig deeper into the data and discover that many of the test set cases are copies of training set examples. Before separating the data, we forgot to remove duplicate entries for the same spam email from our input database. As a result of mistakenly training on part of our test data, we can no longer correctly measure how well our model generalizes to new data.