What is the Difference Between Test and Validation Datasets?

A validation dataset is a sample of data held back from training your model that is used to give an estimate of model skill while tuning model’s hyperparameters.

The validation dataset is different from the test dataset that is also held back from the training of the model, but is instead used to give an unbiased estimate of the skill of the final tuned model when comparing or selecting between final models.

There is much confusion in applied machine learning about what a validation dataset is exactly and how it differs from a test dataset.

In this post, you will discover clear definitions for train, test, and validation datasets and how to use each in your own machine learning projects.

After reading this post, you will know:

  • How experts in the field of machine learning define train, test, and validation datasets.
  • The difference between validation and test datasets in practice.
  • Procedures that you can use to make the best use of validation and test datasets when evaluating your models.

Let’s get started.

What is the Difference Between Test and Validation Datasets?

What is the Difference Between Test and Validation Datasets?
Photo by veddderman, some rights reserved.

Tutorial Overview

This tutorial is divided into 4 parts; they are:

  1. What is a Validation Dataset by the Experts?
  2. Definitions of Train, Validation, and Test Datasets
  3. Validation Dataset is Not Enough
  4. Validation and Test Datasets Disappear

What is a Validation Dataset by the Experts?

I find it useful to see exactly how datasets are described by the practitioners and experts.

In this section, we will take a look at how the train, test, and validation datasets are defined and how they differ according to some of the top machine learning texts and references.

Generally, the term “validation set” is used interchangeably with the term “test set” and refers to a sample of the dataset held back from training the model.

The evaluation of a model skill on the training dataset would result in a biased score. Therefore the model is evaluated on the held-out sample to give an unbiased estimate of model skill. This is typically called a train-test split approach to algorithm evaluation.

Suppose that we would like to estimate the test error associated with fitting a particular statistical learning method on a set of observations. The validation set approach […] is a very simple strategy for this task. It involves randomly dividing the available set of observations into two parts, a training set and a validation set or hold-out set. The model is fit on the training set, and the fitted model is used to predict the responses for the observations in the validation set. The resulting validation set error rate — typically assessed using MSE in the case of a quantitative response—provides an estimate of the test error rate.

— Gareth James, et al., Page 176, An Introduction to Statistical Learning: with Applications in R, 2013.

We can see the interchangeableness directly in Kuhn and Johnson’s excellent text “Applied Predictive Modeling”. In this example, they are clear to point out that the final model evaluation must be performed on a held out dataset that has not been used prior, either for training the model or tuning the model parameters.

Ideally, the model should be evaluated on samples that were not used to build or fine-tune the model, so that they provide an unbiased sense of model effectiveness. When a large amount of data is at hand, a set of samples can be set aside to evaluate the final model. The “training” data set is the general term for the samples used to create the model, while the “test” or “validation” data set is used to qualify performance.

— Max Kuhn and Kjell Johnson, Page 67, Applied Predictive Modeling, 2013

Perhaps traditionally the dataset used to evaluate the final model performance is called the “test set”. The importance of keeping the test set completely separate is reiterated by Russell and Norvig in their seminal AI textbook. They refer to using information from the test set in any way as “peeking”. They suggest locking the test set away completely until all model tuning is complete.

Peeking is a consequence of using test-set performance to both choose a hypothesis and evaluate it. The way to avoid this is to really hold the test set out—lock it away until you are completely done with learning and simply wish to obtain an independent evaluation of the final hypothesis. (And then, if you don’t like the results … you have to obtain, and lock away, a completely new test set if you want to go back and find a better hypothesis.)

— Stuart Russell and Peter Norvig, page 709, Artificial Intelligence: A Modern Approach, 2009 (3rd edition)

Importantly, Russell and Norvig comment that the training dataset used to fit the model can be further split into a training set and a validation set, and that it is this subset of the training dataset, called the validation set, that can be used to get an early estimate of the skill of the model.

If the test set is locked away, but you still want to measure performance on unseen data as a way of selecting a good hypothesis, then divide the available data (without the test set) into a training set and a validation set.

— Stuart Russell and Peter Norvig, page 709,Artificial Intelligence: A Modern Approach, 2009 (3rd edition)

This definition of validation set is corroborated by other seminal texts in the field. A good (and older) example is the glossary of terms in Ripley’s book “Pattern Recognition and Neural Networks.” Specifically, training, validation, and test sets are defined as follows:

– Training set: A set of examples used for learning, that is to fit the parameters of the classifier.

– Validation set: A set of examples used to tune the parameters of a classifier, for example to choose the number of hidden units in a neural network.

– Test set: A set of examples used only to assess the performance of a fully-specified classifier.

— Brian Ripley, page 354, Pattern Recognition and Neural Networks, 1996

These are the recommended definitions and usages of the terms.

A good example that these definitions are canonical is their reiteration in the famous Neural Network FAQ. In addition to reiterating Ripley’s glossary definitions, it goes on to discuss the common misuse of the terms “test set” and “validation set” in applied machine learning.

The literature on machine learning often reverses the meaning of “validation” and “test” sets. This is the most blatant example of the terminological confusion that pervades artificial intelligence research.

The crucial point is that a test set, by the standard definition in the NN [neural net] literature, is never used to choose among two or more networks, so that the error on the test set provides an unbiased estimate of the generalization error (assuming that the test set is representative of the population, etc.).

Subject: What are the population, sample, training set, design set, validation set, and test set?

Do you know of any other clear definitions or usages of these terms, e.g. quotes in papers or textbook?
Please let me know in the comments below.

Definitions of Train, Validation, and Test Datasets

To reiterate the findings from researching the experts above, this section provides unambiguous definitions of the three terms.

  • Training Dataset: The sample of data used to fit the model.
  • Validation Dataset: The sample of data used to provide an unbiased evaluation of a model fit on the training dataset while tuning model hyperparameters. The evaluation becomes more biased as skill on the validation dataset is incorporated into the model configuration.
  • Test Dataset: The sample of data used to provide an unbiased evaluation of a final model fit on the training dataset.

We can make this concrete with a pseudocode sketch:

Below are some additional clarifying notes:

  • The validation dataset may also play a role in other forms of model preparation, such as feature selection.
  • The final model could be fit on the aggregate of the training and validation datasets.

Are these definitions clear to you for your use case?
If not, please ask questions below.

Validation Dataset Is Not Enough

There are other ways of calculating an unbiased, (or progressively more biased in the case of the validation dataset) estimate of model skill on unseen data.

One popular example is to use k-fold cross-validation to tune model hyperparameters instead of a separate validation dataset.

In their book, Kuhn and Johnson have a section titled “Data Splitting Recommendations” in which they layout the limitations of using a sole “test set” (or validation set):

As previously discussed, there is a strong technical case to be made against a single, independent test set:

– A test set is a single evaluation of the model and has limited ability to characterize the uncertainty in the results.
– Proportionally large test sets divide the data in a way that increases bias in the performance estimates.
– With small sample sizes:
– The model may need every possible data point to adequately determine model values.
– The uncertainty of the test set can be considerably large to the point where different test sets may produce very different results.
– Resampling methods can produce reasonable predictions of how well the model will perform on future samples.

— Max Kuhn and Kjell Johnson, Page 78, Applied Predictive Modeling, 2013

They go on to make a recommendation for small sample sizes of using 10-fold cross validation in general because of the desirable low bias and variance properties of the performance estimate. They recommend the bootstrap method in the case of comparing model performance because of the low variance in the performance estimate.

For larger sample sizes, they again recommend a 10-fold cross-validation approach, in general.

Validation and Test Datasets Disappear

It is more than likely that you will not see references to training, validation, and test datasets in modern applied machine learning.

Reference to a “validation dataset” disappears if the practitioner is choosing to tune model hyperparameters using k-fold cross-validation with the training dataset.

We can make this concrete with a pseudocode sketch as follows:

Reference to the “test dataset” too may disappear if the cross-validation of model hyperparameters using the training dataset is nested within a broader cross-validation of the model.

Ultimately, all you are left with is a sample of data from the domain which we may rightly continue to refer to as the training dataset.

Further Reading

This section provides more resources on the topic if you are looking go deeper.

Do you know of any other good resources on this topic? Let me know in the comments below.

Summary

In this tutorial, you discovered that there is much confusion around the terms “validation dataset” and “test dataset” and how you can navigate these terms correctly when evaluating the skill of your own machine learning models.

Specifically, you learned:

  • That there is clear precedent for what “training dataset,” “validation dataset,” and “test dataset” refer to when evaluating models.
  • That the “validation dataset” is predominately used to describe the evaluation of models when tuning hyperparameters and data preparation, and the “test dataset” is predominately used to describe the evaluation of a final tuned model when comparing it to other final models.
  • That the notions of “validation dataset” and “test dataset” may disappear when adopting alternate resampling methods like k-fold cross validation, especially when the resampling methods are nested.

Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.

10 Responses to What is the Difference Between Test and Validation Datasets?

  1. Jacob Sanders July 14, 2017 at 5:11 pm #

    Hey nice article! I’m a fan of your posts here but whenever I try to print these articles to carry with me on the metro to read there are these big floating advertisements for your machine learning tutorials that basically make it unreadable 🙁

    • Jason Brownlee July 15, 2017 at 9:38 am #

      I’m sorry to hear that. Can you send me a photo of an example?

  2. Milind Mahajani July 14, 2017 at 5:59 pm #

    What do we call the set of data on which the final model is run in the field to get answers — this is not labeled data. How do we evaluate the performance of the final model in the field?

    • Jason Brownlee July 15, 2017 at 9:40 am #

      We don’t need to evaluate the performance of the final model (unless as an ongoing maintenance task).

      Generally, we use train/test splits to estimate the skill of the final model. We do this robustly so that the estimate is as accurate as we can make it – to help choose between models and model configs. We use the estimate to know how good our final model is.

      This post will make it clearer:
      http://machinelearningmastery.com/train-final-machine-learning-model/

  3. Helen July 26, 2017 at 6:29 am #

    Hi thank you for nice article. I want to check the model to see if the model is fair and unbiased but my professor told me with cross validation or 10-fold cross validation or any of this methods we can’t confirm if the model is valid and fair. can you please give me some hints about which method I can use for this problem?
    Thanks

    • Jason Brownlee July 26, 2017 at 8:03 am #

      Yes, k-fold cross validation is an excellent way to calculate an unbiased estimate of the skill of your model on unseen data.

  4. René July 26, 2017 at 5:43 pm #

    Nice article, really helped me to refresh my memories.

    One little note: In your first code example you loop over parameters but you never use params in the loop’s body. I guess it should be used in model = fit(train, params)!?

    Keep up the good work!

    • Jason Brownlee July 27, 2017 at 7:55 am #

      Glad to hear it.

      Thanks for the suggestion – updated.

  5. Steven August 1, 2017 at 11:52 am #

    Hi Jason,

    in the pseudocode of the part “Validation and Test Datasets Disappear”, I still didn’t understand how you used k-fold cross-validation to tune model hyperparameters with the training dataset.

    Could you explain the pseudocode?

    Sincerely,
    Steven

    • Jason Brownlee August 2, 2017 at 7:41 am #

      Sure, each set of parameters (param) is evaluated using k-fold cross validation.

      Does that help?

Leave a Reply