{"id":91910,"date":"2025-10-30T18:38:16","date_gmt":"2025-10-30T13:08:16","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=91910"},"modified":"2026-09-09T03:40:32","modified_gmt":"2026-09-08T22:10:32","slug":"training-vs-validation-vs-test-data","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/training-vs-validation-vs-test-data\/","title":{"rendered":"Training vs Validation vs Test Data in Machine Learning"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Quick Answer<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Training data<\/strong> teaches the machine learning model to identify patterns and adjust its internal parameters.<\/li>\n\n\n\n<li><strong>Validation data<\/strong> helps compare models, tune settings, and select the best approach without touching the final test set.<\/li>\n\n\n\n<li><strong>Test data<\/strong> evaluates the selected model on unseen examples and provides the final estimate of real-world performance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Training Data?<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/1-1.png\" alt=\"Illustration showing a machine learning model being trained on 70\u201380% of data with inputs and outputs to learn patterns and relationships\" class=\"wp-image-96236\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/1-1.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/1-1-300x157.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/1-1-768x402.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/1-1-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Training data is the dataset used to teach a <a href=\"https:\/\/www.guvi.in\/blog\/machine-learning-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\">machine learning model<\/a>. 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.<\/p>\n\n\n\n<p><strong>Key points about training data:<\/strong><\/p>\n\n\n\n<ul>\n<li>It makes up about 70-80% of the total dataset.<\/li>\n\n\n\n<li>It contains both input features (like age, experience, salary) and output labels (like promotion: yes or no).<\/li>\n\n\n\n<li>The model uses this data to learn correlations and predict outcomes.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><strong><br><\/strong>If you\u2019re 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Validation Data?<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-1200x630.png\" alt=\"\" class=\"wp-image-138012\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-330-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Validation data is used during model development to compare different models and tune hyperparameters.<\/p>\n\n\n\n<p>The model does not directly learn its parameters from the validation set. Instead, developers use validation results to make decisions such as:<\/p>\n\n\n\n<ul>\n<li>Which algorithm performs best?<\/li>\n\n\n\n<li>What tree depth should be used?<\/li>\n\n\n\n<li>Which regularization value is suitable?<\/li>\n\n\n\n<li>How many training epochs are required?<\/li>\n\n\n\n<li>Which features should be retained?<\/li>\n\n\n\n<li>Has the model started overfitting?<\/li>\n<\/ul>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Test Data?<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-1200x630.png\" alt=\"\" class=\"wp-image-138013\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-331-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Test data is a separate, untouched portion of the dataset used only after model development is complete.<\/p>\n\n\n\n<p>It measures how well the selected model performs on examples it has not seen during training or hyperparameter tuning.<\/p>\n\n\n\n<p>The test set should not influence:<\/p>\n\n\n\n<ul>\n<li>Feature selection<\/li>\n\n\n\n<li>Data-cleaning decisions<\/li>\n\n\n\n<li>Hyperparameter tuning<\/li>\n\n\n\n<li>Algorithm selection<\/li>\n\n\n\n<li>Classification thresholds<\/li>\n\n\n\n<li>Early stopping<\/li>\n\n\n\n<li>Model architecture<\/li>\n<\/ul>\n\n\n\n<p>Using the test set only once, after all major decisions are finalized, provides a more honest estimate of model performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Training vs Validation vs Test Data<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Feature<\/th><th>Training Data<\/th><th>Validation Data<\/th><th>Test Data<\/th><\/tr><tr><td>Main purpose<\/td><td>Teaches the model<\/td><td>Helps tune and select the model<\/td><td>Measures final performance<\/td><\/tr><tr><td>Used during model fitting<\/td><td>Yes<\/td><td>No<\/td><td>No<\/td><\/tr><tr><td>Influences model parameters<\/td><td>Directly<\/td><td>Indirectly through model-selection decisions<\/td><td>Should not influence them<\/td><\/tr><tr><td>Used for hyperparameter tuning<\/td><td>No<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Used for feature selection<\/td><td>May be used to learn transformations<\/td><td>Used to compare selected features<\/td><td>No<\/td><\/tr><tr><td>Seen during development<\/td><td>Frequently<\/td><td>Frequently<\/td><td>Ideally only at the end<\/td><\/tr><tr><td>Typical proportion<\/td><td>Around 60\u201380%<\/td><td>Around 10\u201320%<\/td><td>Around 10\u201320%<\/td><\/tr><tr><td>Main question answered<\/td><td>What patterns can the model learn?<\/td><td>Which model or configuration is best?<\/td><td>How well will the final model generalize?<\/td><\/tr><tr><td>Risk when misused<\/td><td>Underfitting, overfitting, or biased learning<\/td><td>Overfitting to validation results<\/td><td>Test leakage and overly optimistic results<\/td><\/tr><tr><td>Example<\/td><td>Historical employee records used for learning<\/td><td>Records used to compare model settings<\/td><td>Untouched records used for final evaluation<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>These percentages are guidelines rather than fixed rules. The correct split depends on dataset size, class balance, data collection method, and the business problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Training vs Validation vs Test: Why Three Splits, Not Two?<\/h2>\n\n\n\n<p>A two-way train-test split works for simple exercises where no major model-selection decisions are made.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Training Set<\/h3>\n\n\n\n<p>The training set answers:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>What should the model learn?<\/p>\n<\/blockquote>\n\n\n\n<p>The algorithm uses this data to estimate weights, tree rules, cluster centres, or other learned parameters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Validation Set<\/h3>\n\n\n\n<p>The validation set answers:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>Which model or configuration should be selected?<\/p>\n<\/blockquote>\n\n\n\n<p>Developers may compare several models and choose the one that performs best on validation data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Test Set<\/h3>\n\n\n\n<p>The test set answers:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>How well does the final selected model perform on unseen data?<\/p>\n<\/blockquote>\n\n\n\n<p>The test result should represent final performance rather than guide further improvements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What Goes Wrong With Only Two Splits?<\/h3>\n\n\n\n<p>Suppose a developer tests 30 model configurations on the same test set and selects the highest-scoring one.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Three splits create a cleaner separation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Training data   \u2192 Learn model parameters\nValidation data \u2192 Select model and tune settings\nTest data       \u2192 Report final performance<\/code><\/pre>\n\n\n\n<p>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\u2019s guidance warns that learning and testing on the same data produces misleading performance estimates.<\/p>\n\n\n\n<p>If you\u2019re exploring how concepts like training and testing data fit into the broader world of data science, the <a href=\"https:\/\/www.guvi.in\/mlp\/data-science-ebook?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=training-vs-validation-vs-test-data\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Data Science eBook<\/strong><\/a> is a great next step. It covers key topics such as Python basics, data preprocessing, visualization, and model building \u2014 all explained in simple terms with real-world examples. It\u2019s a handy guide to strengthen your data science foundation at your own pace.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Is Data Split Into Training, Validation, and Test Sets?<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-1200x630.png\" alt=\"\" class=\"wp-image-138014\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/image-332-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>A machine learning <a href=\"https:\/\/www.guvi.in\/blog\/best-datasets-for-data-science-projects\/\">dataset<\/a> is usually divided into three separate parts. Each part supports a different stage of model development.<\/p>\n\n\n\n<ul>\n<li><strong>Training data<\/strong> helps the model learn patterns.<\/li>\n\n\n\n<li><strong>Validation data<\/strong> helps compare models and tune hyperparameters.<\/li>\n\n\n\n<li><strong>Test data<\/strong> measures final performance on unseen examples.<\/li>\n<\/ul>\n\n\n\n<p>A common split ratio is:<\/p>\n\n\n\n<ul>\n<li><strong>70% training<\/strong><\/li>\n\n\n\n<li><strong>15% validation<\/strong><\/li>\n\n\n\n<li><strong>15% testing<\/strong><\/li>\n<\/ul>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Consider a dataset containing 1,000 customer records:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Dataset<\/th><th>Number of Records<\/th><th>Purpose<\/th><\/tr><tr><td>Training set<\/td><td>700<\/td><td>Teaches the model<\/td><\/tr><tr><td>Validation set<\/td><td>150<\/td><td>Tunes and compares models<\/td><\/tr><tr><td>Test set<\/td><td>150<\/td><td>Measures final performance<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The test set must remain untouched until the model and its settings are finalized.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Stratified splitting is useful for imbalanced classification datasets because it keeps class proportions similar across all three sets.<\/p>\n\n\n\n<p><em>Explore: <a href=\"https:\/\/www.guvi.in\/blog\/concept-of-datafication\/\" target=\"_blank\" rel=\"noreferrer noopener\">The Concept of Datafication: Definition &amp; Examples<\/a><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Methods for Splitting Data<\/h2>\n\n\n\n<p>While random splitting is most common, there are several structured methods to ensure reliable evaluation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Hold-Out Method<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/6-1.png\" alt=\"A simple diagram showing a dataset divided into two parts labeled Training Data (80%) and Testing Data (20%) , representing the Hold-Out Method.\n\" class=\"wp-image-96242\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/6-1.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/6-1-300x157.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/6-1-768x402.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/6-1-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li>The simplest approach is where data is divided into two parts \u2014 training and testing (e.g., 80\/20 or 70\/30).<\/li>\n\n\n\n<li>Works well for large datasets.<\/li>\n\n\n\n<li>Quick and efficient but may produce slightly different results with small datasets.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. K-Fold <a href=\"https:\/\/www.guvi.in\/blog\/cross-validation-in-machine-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Cross-Validation<\/strong><\/a><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/7-1.png\" alt=\"An illustration showing K-Fold Cross-Validation\" class=\"wp-image-96243\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/7-1.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/7-1-300x157.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/7-1-768x402.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/7-1-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li>The dataset is divided into K equal parts (folds).<\/li>\n\n\n\n<li>The model is trained K times \u2014 each time using a different fold for testing and the rest for training.<\/li>\n\n\n\n<li>The final score is the average performance across all K runs.<\/li>\n\n\n\n<li>Common values for K are 5 or 10.<\/li>\n\n\n\n<li>This method gives a more stable and unbiased performance estimate.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. Stratified K-Fold Cross-Validation<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/8-1.png\" alt=\" A visual showing Stratified K-Fold Cross-Validation\" class=\"wp-image-96244\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/8-1.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/8-1-300x157.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/8-1-768x402.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/8-1-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li>A variation of K-Fold is used when datasets are imbalanced (for example, more \u201cNo\u201d than \u201cYes\u201d labels).<\/li>\n\n\n\n<li>Ensures each fold maintains the same proportion of class labels as the original dataset.<\/li>\n\n\n\n<li>This provides a fair evaluation across all categories.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. Leave-One-Out Cross-Validation (LOOCV)<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/9-1.png\" alt=\"An infographic for Leave-One-Out Cross-Validation (LOOCV)\" class=\"wp-image-96245\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/9-1.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/9-1-300x157.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/9-1-768x402.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/9-1-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li>A special case of K-Fold where K equals the number of data points.<\/li>\n\n\n\n<li>Each sample is used once for testing, while all others are used for training.<\/li>\n\n\n\n<li>Extremely accurate but computationally expensive for large datasets.<\/li>\n<\/ul>\n\n\n\n<p>If you prefer learning through short, structured lessons, check out HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/mlp\/data-science-email-course?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=training-vs-validation-vs-test-data\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>5-day free Data Science Email Series<\/strong><\/a>. You\u2019ll 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Splitting Training, Validation, and Test Data With Scikit-Learn<\/h2>\n\n\n\n<p>Scikit-learn\u2019s <code>train_test_split<\/code> function creates randomized subsets from arrays or matrices. A three-way split can be produced by calling it twice.<\/p>\n\n\n\n<p>The following example creates:<\/p>\n\n\n\n<ul>\n<li>70% training data<\/li>\n\n\n\n<li>15% validation data<\/li>\n\n\n\n<li>15% test data<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.datasets import load_breast_cancer\nfrom sklearn.model_selection import train_test_split\n\n# Load example features and labels\nX, y = load_breast_cancer(return_X_y=True)\n\n# First, reserve 15% as the untouched test set.\nX_development, X_test, y_development, y_test = train_test_split(\n    X,\n    y,\n    test_size=0.15,\n    random_state=42,\n    stratify=y\n)\n\n# 15% of the complete dataset equals about 17.65% of\n# the remaining 85% development data.\nX_train, X_validation, y_train, y_validation = train_test_split(\n    X_development,\n    y_development,\n    test_size=0.1765,\n    random_state=42,\n    stratify=y_development\n)\n\nprint(\"Training samples:\", len(X_train))\nprint(\"Validation samples:\", len(X_validation))\nprint(\"Test samples:\", len(X_test))<\/code><\/pre>\n\n\n\n<p>The <code>random_state<\/code> value makes the split reproducible. The <code>stratify<\/code> argument maintains approximately the same class proportions in each subset.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Train and Evaluate a Model<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import StandardScaler\n\nmodel = make_pipeline(\n    StandardScaler(),\n    LogisticRegression(max_iter=2000)\n)\n\n# Learn only from the training set.\nmodel.fit(X_train, y_train)\n\n# Use validation performance for development decisions.\nvalidation_predictions = model.predict(X_validation)\nvalidation_accuracy = accuracy_score(\n    y_validation,\n    validation_predictions\n)\n\nprint(\"Validation accuracy:\", validation_accuracy)<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\n\nX_final_train = np.concatenate(\n    &#91;X_train, X_validation],\n    axis=0\n)\ny_final_train = np.concatenate(\n    &#91;y_train, y_validation],\n    axis=0\n)\n\nfinal_model = make_pipeline(\n    StandardScaler(),\n    LogisticRegression(max_iter=2000)\n)\n\nfinal_model.fit(X_final_train, y_final_train)\n\ntest_predictions = final_model.predict(X_test)\ntest_accuracy = accuracy_score(y_test, test_predictions)\n\nprint(\"Final test accuracy:\", test_accuracy)<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using Cross-Validation With <code>cross_val_score<\/code><\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Scikit-learn\u2019s <code>cross_val_score<\/code> trains and evaluates an estimator repeatedly using the selected cross-validation strategy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.datasets import load_breast_cancer\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import (\n    StratifiedKFold,\n    cross_val_score,\n    train_test_split\n)\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import StandardScaler\n\nX, y = load_breast_cancer(return_X_y=True)\n\n# Keep the final test set untouched.\nX_development, X_test, y_development, y_test = train_test_split(\n    X,\n    y,\n    test_size=0.20,\n    random_state=42,\n    stratify=y\n)\n\nmodel = make_pipeline(\n    StandardScaler(),\n    LogisticRegression(max_iter=2000)\n)\n\ncross_validator = StratifiedKFold(\n    n_splits=5,\n    shuffle=True,\n    random_state=42\n)\n\nscores = cross_val_score(\n    model,\n    X_development,\n    y_development,\n    cv=cross_validator,\n    scoring=\"accuracy\"\n)\n\nprint(\"Fold scores:\", scores)\nprint(\"Mean validation accuracy:\", scores.mean())\nprint(\"Score standard deviation:\", scores.std())<\/code><\/pre>\n\n\n\n<p>Every fold acts as validation data once, while the remaining folds are used for training.<\/p>\n\n\n\n<p>After model selection, train the final model using the complete development set:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.metrics import accuracy_score\n\nmodel.fit(X_development, y_development)\n\ntest_predictions = model.predict(X_test)\ntest_accuracy = accuracy_score(y_test, test_predictions)\n\nprint(\"Final test accuracy:\", test_accuracy)<\/code><\/pre>\n\n\n\n<p>The test set remains separate throughout cross-validation. It is used only after the algorithm and configuration have been finalized.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Happens If Training Data Has Bias? A Real Example<\/h2>\n\n\n\n<p>Biased training data can cause a model to perform well for well-represented groups and poorly for underrepresented groups.<\/p>\n\n\n\n<p>Bias may enter training data through:<\/p>\n\n\n\n<ul>\n<li>Unequal demographic representation<\/li>\n\n\n\n<li>Historical discrimination<\/li>\n\n\n\n<li>Incorrect or subjective labels<\/li>\n\n\n\n<li>Missing records<\/li>\n\n\n\n<li>Measurement errors<\/li>\n\n\n\n<li>Sampling from a narrow population<\/li>\n\n\n\n<li>Using proxy variables for sensitive attributes<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Real Example: Facial-Analysis Systems<\/h3>\n\n\n\n<p>The <a href=\"https:\/\/proceedings.mlr.press\/v81\/buolamwini18a\/buolamwini18a.pdf\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/proceedings.mlr.press\/v81\/buolamwini18a\/buolamwini18a.pdf\" rel=\"noreferrer noopener nofollow\">Gender Shades study<\/a> 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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Unequal representation is not always the only source of model bias. Labels, image quality, collection methods, model design, and deployment conditions may also contribute.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Training Bias Affects a Model<\/h3>\n\n\n\n<p>A biased dataset can lead to:<\/p>\n\n\n\n<ul>\n<li>Higher error rates for underrepresented groups<\/li>\n\n\n\n<li>Unfair approval or rejection decisions<\/li>\n\n\n\n<li>Poor performance after deployment<\/li>\n\n\n\n<li>Misleading overall accuracy<\/li>\n\n\n\n<li>Legal and reputational risks<\/li>\n\n\n\n<li>Reduced user trust<\/li>\n<\/ul>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to Reduce Training-Data Bias<\/h3>\n\n\n\n<p>Teams should:<\/p>\n\n\n\n<ul>\n<li>Examine representation across important groups.<\/li>\n\n\n\n<li>Review how examples and labels were collected.<\/li>\n\n\n\n<li>Measure performance separately across relevant subgroups.<\/li>\n\n\n\n<li>Improve coverage where important populations are missing.<\/li>\n\n\n\n<li>Remove inappropriate proxy variables.<\/li>\n\n\n\n<li>Document known dataset limitations.<\/li>\n\n\n\n<li>Monitor predictions after deployment.<\/li>\n\n\n\n<li>Include domain experts in data and model reviews.<\/li>\n<\/ul>\n\n\n\n<p>Adding more data does not automatically solve bias. The new data must address the missing populations, situations, and failure cases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Data-Splitting Mistakes in Machine Learning Projects<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Preprocessing Before Splitting<\/h3>\n\n\n\n<p>Scaling, imputing, feature selection, or encoding the complete dataset before splitting allows information from the validation or test set to affect training.<\/p>\n\n\n\n<p>Split first and fit preprocessing steps only on the training data. A pipeline helps apply the same fitted transformations safely.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Using the Test Set for Model Tuning<\/h3>\n\n\n\n<p>Checking test performance after every model change turns the test set into an unofficial validation set.<\/p>\n\n\n\n<p>Keep it hidden until the model, features, thresholds, and hyperparameters are finalized.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Randomly Splitting Time-Series Data<\/h3>\n\n\n\n<p>A random split may place future observations in the training set and older observations in the test set.<\/p>\n\n\n\n<p>This creates future-data leakage. Time-based problems should preserve chronological order. Scikit-learn provides <code>TimeSeriesSplit<\/code> for time-ordered data where standard cross-validation would train on future observations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Ignoring Class Imbalance<\/h3>\n\n\n\n<p>A random split may place too few minority-class examples in one subset.<\/p>\n\n\n\n<p>Use stratification for classification problems when appropriate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>X_train, X_test, y_train, y_test = train_test_split(\n    X,\n    y,\n    test_size=0.20,\n    stratify=y,\n    random_state=42\n)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. Splitting Related Records Across Sets<\/h3>\n\n\n\n<p>Records belonging to the same person, customer, patient, device, or household should not appear across both training and test sets.<\/p>\n\n\n\n<p>The model may memorize entity-specific patterns rather than learn general relationships. Group-based splitting is more suitable in such cases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. Leaving Duplicate Records Across Splits<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. Using a Test Set That Is Too Small<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. Choosing the Split Ratio Mechanically<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. Ignoring Data Distribution Changes<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. Applying Data Augmentation Before Splitting<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Clear separation between all three datasets helps teams build models that perform well during development and remain dependable in real-world use.<\/p>\n\n\n\n<p>If you\u2019re eager to strengthen your foundation in data science and learn practical skills like data preparation, visualization, and model building, consider joining the <a href=\"https:\/\/www.guvi.in\/zen-class\/data-science-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=training-vs-validation-vs-test-data\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Data Science Course<\/strong><\/a>. 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1761802174352\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>1. Can I use the same dataset for training and testing?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No, because it will make the model memorize the data, leading to poor real-world performance.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1761802191685\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>2. What if my dataset is too small to split?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>In that case, you can use <strong>cross-validation<\/strong>, which splits data into multiple smaller sets for better evaluation.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1761802211108\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>3. How can I know if my model is overfitting?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>If your model performs very well on training data but poorly on testing data, it\u2019s likely overfitting.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1761802233892\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>4. Can I use a different split ratio than 80\/20?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p> Yes, depending on your dataset size. For large datasets, even 90\/10 can work well.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1761802266414\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>5. Should I include outliers in training and testing data?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can include them, but always analyze their impact \u2014 sometimes they improve learning, other times they distort results.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":60,"featured_media":138015,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"views":"5279","authorinfo":{"name":"Vaishali","url":"https:\/\/www.guvi.in\/blog\/author\/vaishali\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/09\/IMG_4280-300x116.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/91910"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=91910"}],"version-history":[{"count":17,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/91910\/revisions"}],"predecessor-version":[{"id":138016,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/91910\/revisions\/138016"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/138015"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=91910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=91910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=91910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}