Training vs Validation vs Test Data in Machine Learning
Jul 21, 2026 7 Min Read 4728 Views
(Last Updated)
A machine learning model does not learn, improve, and prove its accuracy using the same data. The complete dataset is usually divided into training, validation, and test sets, with each serving a different purpose.
Training data teaches the model, validation data helps refine it, and test data measures its final performance on unseen examples. This guide explains how these datasets differ, how to split them correctly, and which mistakes can make model results unreliable.
Quick Answer
- Training data teaches the machine learning model to identify patterns and adjust its internal parameters.
- Validation data helps compare models, tune settings, and select the best approach without touching the final test set.
- Test data evaluates the selected model on unseen examples and provides the final estimate of real-world performance.
Table of contents
- What Is Training Data?
- What Is Validation Data?
- What Is Test Data?
- Training vs Validation vs Test Data
- Training vs Validation vs Test: Why Three Splits, Not Two?
- Training Set
- Validation Set
- Test Set
- What Goes Wrong With Only Two Splits?
- How Is Data Split Into Training, Validation, and Test Sets?
- Common Methods for Splitting Data
- Hold-Out Method
- K-Fold Cross-Validation
- Stratified K-Fold Cross-Validation
- Leave-One-Out Cross-Validation (LOOCV)
- Splitting Training, Validation, and Test Data With Scikit-Learn
- Train and Evaluate a Model
- Using Cross-Validation With cross_val_score
- What Happens If Training Data Has Bias? A Real Example
- Real Example: Facial-Analysis Systems
- How Training Bias Affects a Model
- How to Reduce Training-Data Bias
- Common Data-Splitting Mistakes in Machine Learning Projects
- Preprocessing Before Splitting
- Using the Test Set for Model Tuning
- Randomly Splitting Time-Series Data
- Ignoring Class Imbalance
- Splitting Related Records Across Sets
- Leaving Duplicate Records Across Splits
- Using a Test Set That Is Too Small
- Choosing the Split Ratio Mechanically
- Ignoring Data Distribution Changes
- Applying Data Augmentation Before Splitting
- Conclusion
- FAQs
- Can I use the same dataset for training and testing?
- What if my dataset is too small to split?
- How can I know if my model is overfitting?
- Can I use a different split ratio than 80/20?
- Should I include outliers in training and testing data?
What Is Training Data?

Training data is the dataset used to teach a machine learning model. It contains examples that help the model understand patterns, relationships, and trends. The model analyzes this data repeatedly, adjusting its parameters to reduce errors and improve accuracy.
Key points about training data:
- It makes up about 70-80% of the total dataset.
- It contains both input features (like age, experience, salary) and output labels (like promotion: yes or no).
- The model uses this data to learn correlations and predict outcomes.
Example:
If you’re training a model to predict employee promotions, the training data will include employee details (experience, salary, performance score) and whether they were promoted. The model learns from these examples before it sees any new data.
What Is Validation Data?
Validation data is used during model development to compare different models and tune hyperparameters.
The model does not directly learn its parameters from the validation set. Instead, developers use validation results to make decisions such as:
- Which algorithm performs best?
- What tree depth should be used?
- Which regularization value is suitable?
- How many training epochs are required?
- Which features should be retained?
- Has the model started overfitting?
Suppose three promotion-prediction models are trained using logistic regression, a decision tree, and a random forest. Their validation scores can help select the most suitable model before final testing.
Repeatedly checking the test set while making these decisions would indirectly tune the model to the test data. The validation set prevents this problem by acting as a development-time evaluation set.
What Is Test Data?
Test data is a separate, untouched portion of the dataset used only after model development is complete.
It measures how well the selected model performs on examples it has not seen during training or hyperparameter tuning.
The test set should not influence:
- Feature selection
- Data-cleaning decisions
- Hyperparameter tuning
- Algorithm selection
- Classification thresholds
- Early stopping
- Model architecture
Using the test set only once, after all major decisions are finalized, provides a more honest estimate of model performance.
Training vs Validation vs Test Data
| Feature | Training Data | Validation Data | Test Data |
|---|---|---|---|
| Main purpose | Teaches the model | Helps tune and select the model | Measures final performance |
| Used during model fitting | Yes | No | No |
| Influences model parameters | Directly | Indirectly through model-selection decisions | Should not influence them |
| Used for hyperparameter tuning | No | Yes | No |
| Used for feature selection | May be used to learn transformations | Used to compare selected features | No |
| Seen during development | Frequently | Frequently | Ideally only at the end |
| Typical proportion | Around 60–80% | Around 10–20% | Around 10–20% |
| Main question answered | What patterns can the model learn? | Which model or configuration is best? | How well will the final model generalize? |
| Risk when misused | Underfitting, overfitting, or biased learning | Overfitting to validation results | Test leakage and overly optimistic results |
| Example | Historical employee records used for learning | Records used to compare model settings | Untouched records used for final evaluation |
These percentages are guidelines rather than fixed rules. The correct split depends on dataset size, class balance, data collection method, and the business problem.
Training vs Validation vs Test: Why Three Splits, Not Two?
A two-way train-test split works for simple exercises where no major model-selection decisions are made.
Most real machine learning projects involve comparing algorithms, choosing features, tuning hyperparameters, adjusting thresholds, and repeating experiments. A separate validation set is needed for these decisions.
Training Set
The training set answers:
What should the model learn?
The algorithm uses this data to estimate weights, tree rules, cluster centres, or other learned parameters.
Validation Set
The validation set answers:
Which model or configuration should be selected?
Developers may compare several models and choose the one that performs best on validation data.
Test Set
The test set answers:
How well does the final selected model perform on unseen data?
The test result should represent final performance rather than guide further improvements.
What Goes Wrong With Only Two Splits?
Suppose a developer tests 30 model configurations on the same test set and selects the highest-scoring one.
Although the model was not directly trained on those test examples, repeated test-set evaluation influenced the final selection. The reported test score may therefore be overly optimistic.
Three splits create a cleaner separation:
Training data → Learn model parameters
Validation data → Select model and tune settings
Test data → Report final performance
Cross-validation can replace a single validation set when data is limited. However, an independent test set should still remain untouched until the final evaluation. Scikit-learn’s guidance warns that learning and testing on the same data produces misleading performance estimates.
If you’re exploring how concepts like training and testing data fit into the broader world of data science, the Data Science eBook is a great next step. It covers key topics such as Python basics, data preprocessing, visualization, and model building — all explained in simple terms with real-world examples. It’s a handy guide to strengthen your data science foundation at your own pace.
How Is Data Split Into Training, Validation, and Test Sets?
A machine learning dataset is usually divided into three separate parts. Each part supports a different stage of model development.
- Training data helps the model learn patterns.
- Validation data helps compare models and tune hyperparameters.
- Test data measures final performance on unseen examples.
A common split ratio is:
- 70% training
- 15% validation
- 15% testing
Other ratios, such as 60/20/20 or 80/10/10, may also work. The right ratio depends on the dataset size, class distribution, and project requirements.
Consider a dataset containing 1,000 customer records:
| Dataset | Number of Records | Purpose |
|---|---|---|
| Training set | 700 | Teaches the model |
| Validation set | 150 | Tunes and compares models |
| Test set | 150 | Measures final performance |
The test set must remain untouched until the model and its settings are finalized.
Random splitting works well when individual records are independent. Time-series data should usually be split chronologically. Records belonging to the same customer, patient, household, or device should also remain within one subset.
Stratified splitting is useful for imbalanced classification datasets because it keeps class proportions similar across all three sets.
Explore: The Concept of Datafication: Definition & Examples
Common Methods for Splitting Data
While random splitting is most common, there are several structured methods to ensure reliable evaluation.
1. Hold-Out Method

- The simplest approach is where data is divided into two parts — training and testing (e.g., 80/20 or 70/30).
- Works well for large datasets.
- Quick and efficient but may produce slightly different results with small datasets.
2. K-Fold Cross-Validation

- The dataset is divided into K equal parts (folds).
- The model is trained K times — each time using a different fold for testing and the rest for training.
- The final score is the average performance across all K runs.
- Common values for K are 5 or 10.
- This method gives a more stable and unbiased performance estimate.
3. Stratified K-Fold Cross-Validation

- A variation of K-Fold is used when datasets are imbalanced (for example, more “No” than “Yes” labels).
- Ensures each fold maintains the same proportion of class labels as the original dataset.
- This provides a fair evaluation across all categories.
4. Leave-One-Out Cross-Validation (LOOCV)

- A special case of K-Fold where K equals the number of data points.
- Each sample is used once for testing, while all others are used for training.
- Extremely accurate but computationally expensive for large datasets.
If you prefer learning through short, structured lessons, check out HCL GUVI’s 5-day free Data Science Email Series. You’ll receive bite-sized lessons each day covering key concepts like data analysis, visualization, and model evaluation, making it easy to learn data science fundamentals step by step, right in your inbox.
Splitting Training, Validation, and Test Data With Scikit-Learn
Scikit-learn’s train_test_split function creates randomized subsets from arrays or matrices. A three-way split can be produced by calling it twice.
The following example creates:
- 70% training data
- 15% validation data
- 15% test data
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
# Load example features and labels
X, y = load_breast_cancer(return_X_y=True)
# First, reserve 15% as the untouched test set.
X_development, X_test, y_development, y_test = train_test_split(
X,
y,
test_size=0.15,
random_state=42,
stratify=y
)
# 15% of the complete dataset equals about 17.65% of
# the remaining 85% development data.
X_train, X_validation, y_train, y_validation = train_test_split(
X_development,
y_development,
test_size=0.1765,
random_state=42,
stratify=y_development
)
print("Training samples:", len(X_train))
print("Validation samples:", len(X_validation))
print("Test samples:", len(X_test))
The random_state value makes the split reproducible. The stratify argument maintains approximately the same class proportions in each subset.
Train and Evaluate a Model
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
model = make_pipeline(
StandardScaler(),
LogisticRegression(max_iter=2000)
)
# Learn only from the training set.
model.fit(X_train, y_train)
# Use validation performance for development decisions.
validation_predictions = model.predict(X_validation)
validation_accuracy = accuracy_score(
y_validation,
validation_predictions
)
print("Validation accuracy:", validation_accuracy)
After selecting the final model and settings, combine the training and validation data, fit the model again, and evaluate it once on the untouched test set.
import numpy as np
X_final_train = np.concatenate(
[X_train, X_validation],
axis=0
)
y_final_train = np.concatenate(
[y_train, y_validation],
axis=0
)
final_model = make_pipeline(
StandardScaler(),
LogisticRegression(max_iter=2000)
)
final_model.fit(X_final_train, y_final_train)
test_predictions = final_model.predict(X_test)
test_accuracy = accuracy_score(y_test, test_predictions)
print("Final test accuracy:", test_accuracy)
Preprocessing is placed inside a pipeline so that the scaler learns only from the relevant training portion. This prevents information from validation or test records from leaking into the fitted transformation. Scikit-learn recommends splitting data before preprocessing and using pipelines to reduce leakage risk.
Using Cross-Validation With cross_val_score
A single validation split can produce unstable results, especially when the dataset is small. Cross-validation evaluates the model across several different train-validation divisions.
Scikit-learn’s cross_val_score trains and evaluates an estimator repeatedly using the selected cross-validation strategy.
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import (
StratifiedKFold,
cross_val_score,
train_test_split
)
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X, y = load_breast_cancer(return_X_y=True)
# Keep the final test set untouched.
X_development, X_test, y_development, y_test = train_test_split(
X,
y,
test_size=0.20,
random_state=42,
stratify=y
)
model = make_pipeline(
StandardScaler(),
LogisticRegression(max_iter=2000)
)
cross_validator = StratifiedKFold(
n_splits=5,
shuffle=True,
random_state=42
)
scores = cross_val_score(
model,
X_development,
y_development,
cv=cross_validator,
scoring="accuracy"
)
print("Fold scores:", scores)
print("Mean validation accuracy:", scores.mean())
print("Score standard deviation:", scores.std())
Every fold acts as validation data once, while the remaining folds are used for training.
After model selection, train the final model using the complete development set:
from sklearn.metrics import accuracy_score
model.fit(X_development, y_development)
test_predictions = model.predict(X_test)
test_accuracy = accuracy_score(y_test, test_predictions)
print("Final test accuracy:", test_accuracy)
The test set remains separate throughout cross-validation. It is used only after the algorithm and configuration have been finalized.
What Happens If Training Data Has Bias? A Real Example
Biased training data can cause a model to perform well for well-represented groups and poorly for underrepresented groups.
Bias may enter training data through:
- Unequal demographic representation
- Historical discrimination
- Incorrect or subjective labels
- Missing records
- Measurement errors
- Sampling from a narrow population
- Using proxy variables for sensitive attributes
Real Example: Facial-Analysis Systems
The Gender Shades study evaluated commercial gender-classification systems and examined commonly used facial-analysis datasets. The researchers reported that two benchmark datasets were heavily composed of lighter-skinned people.
The evaluated systems showed their highest error rates for darker-skinned women. Error rates reached 34.7% for that group, compared with a maximum error rate of 0.8% for lighter-skinned men in the study.
NIST has also tested demographic differences across face-recognition algorithms using millions of images. Its work has documented that error rates can vary across demographic groups and algorithms.
Unequal representation is not always the only source of model bias. Labels, image quality, collection methods, model design, and deployment conditions may also contribute.
How Training Bias Affects a Model
A biased dataset can lead to:
- Higher error rates for underrepresented groups
- Unfair approval or rejection decisions
- Poor performance after deployment
- Misleading overall accuracy
- Legal and reputational risks
- Reduced user trust
A model may report 95% overall accuracy and still perform poorly for a smaller subgroup. Evaluation should therefore include relevant subgroup-level metrics rather than only one combined score.
How to Reduce Training-Data Bias
Teams should:
- Examine representation across important groups.
- Review how examples and labels were collected.
- Measure performance separately across relevant subgroups.
- Improve coverage where important populations are missing.
- Remove inappropriate proxy variables.
- Document known dataset limitations.
- Monitor predictions after deployment.
- Include domain experts in data and model reviews.
Adding more data does not automatically solve bias. The new data must address the missing populations, situations, and failure cases.
Common Data-Splitting Mistakes in Machine Learning Projects
1. Preprocessing Before Splitting
Scaling, imputing, feature selection, or encoding the complete dataset before splitting allows information from the validation or test set to affect training.
Split first and fit preprocessing steps only on the training data. A pipeline helps apply the same fitted transformations safely.
2. Using the Test Set for Model Tuning
Checking test performance after every model change turns the test set into an unofficial validation set.
Keep it hidden until the model, features, thresholds, and hyperparameters are finalized.
3. Randomly Splitting Time-Series Data
A random split may place future observations in the training set and older observations in the test set.
This creates future-data leakage. Time-based problems should preserve chronological order. Scikit-learn provides TimeSeriesSplit for time-ordered data where standard cross-validation would train on future observations.
4. Ignoring Class Imbalance
A random split may place too few minority-class examples in one subset.
Use stratification for classification problems when appropriate:
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=0.20,
stratify=y,
random_state=42
)
5. Splitting Related Records Across Sets
Records belonging to the same person, customer, patient, device, or household should not appear across both training and test sets.
The model may memorize entity-specific patterns rather than learn general relationships. Group-based splitting is more suitable in such cases.
6. Leaving Duplicate Records Across Splits
Duplicate or nearly identical records can create inflated evaluation scores. Duplicates should be identified before splitting, or all versions of the same example should remain within one subset.
7. Using a Test Set That Is Too Small
A tiny test set may produce unstable metrics. A few correct or incorrect predictions can change the reported result substantially. The test set should contain enough examples to represent important classes and operating conditions.
8. Choosing the Split Ratio Mechanically
An 80/20 split is common, but it is not always correct. A dataset containing millions of records may need only a small test percentage. A small dataset may benefit from cross-validation rather than a large permanent validation set.
9. Ignoring Data Distribution Changes
Training and test data drawn from the same historical period may not represent future users or conditions. Teams should examine seasonality, geography, device types, policy changes, and other sources of distribution shift.
10. Applying Data Augmentation Before Splitting
Creating transformed copies before the split may place the original record in training and a slightly modified copy in testing. Split the original records first. Apply augmentation only to the training subset.
Conclusion
Training, validation, and test data each support a different stage of machine learning development. Training data helps the model learn patterns, validation data helps refine its settings, and test data measures its final performance on unseen examples.
A correct data split prevents leakage, reduces overfitting, and produces more reliable evaluation results. The split ratio should match the dataset size, class balance, time order, and project requirements rather than follow one fixed formula.
Clear separation between all three datasets helps teams build models that perform well during development and remain dependable in real-world use.
If you’re eager to strengthen your foundation in data science and learn practical skills like data preparation, visualization, and model building, consider joining the Data Science Course. This program offers mentor-led training, hands-on projects, and job-ready modules covering Python, Machine Learning, and Data Visualization, helping you become confident in applying these concepts in real-world scenarios.
FAQs
1. Can I use the same dataset for training and testing?
No, because it will make the model memorize the data, leading to poor real-world performance.
2. What if my dataset is too small to split?
In that case, you can use cross-validation, which splits data into multiple smaller sets for better evaluation.
3. How can I know if my model is overfitting?
If your model performs very well on training data but poorly on testing data, it’s likely overfitting.
4. Can I use a different split ratio than 80/20?
Yes, depending on your dataset size. For large datasets, even 90/10 can work well.
5. Should I include outliers in training and testing data?
You can include them, but always analyze their impact — sometimes they improve learning, other times they distort results.



Did you enjoy this article?