Train-Validation-Test Split: Tune Without Biasing the Final Estimate

Learn what each data split is allowed to do, then follow a stratified churn example from model selection to one protected final estimate.

KnowledgeGate Team

Exam prep & CS education

Updated 3 Dec 20266 min read
Train-Validation-Test Split: Tune Without Biasing the Final Estimate

A model can seem to improve every time you check the test score. The danger is that each threshold, feature, or hyperparameter change then adapts to the same test sample, so the score rises without stronger generalisation. A clean workflow gives training data one job, validation data one job, and test data one protected final job. The wider ML & Data Science hub places the workflow in context.

Train, validation and test data each answer a different question

Training data fits coefficients, tree splits, neural-network weights and learned preprocessing. Validation data compares model families, hyperparameters, features, thresholds and stopping points. Test data is opened after those choices are frozen to estimate how the selected pipeline performs on unseen cases from the intended population.

split

allowed decisions

forbidden use

question answered

Training

Fit parameters and learned transformations

Select a model from its training score

What can the model learn?

Validation

Select model, settings and threshold

Fit parameters or report a final estimate

Which candidate should be frozen?

Test

Report predeclared metrics once

Trigger another tuning loop

How does the frozen pipeline estimate performance?

This supervised-evaluation pattern suits labelled predictive models. Unsupervised systems, forecasting problems and rule-based AI need evaluation designs matched to their own deployment units and outcomes.

Build a stratified 70/15/15 split from 1,000 labelled rows

Consider an illustrative binary churn dataset containing 1,000 independent customer records: 600 non-churn cases (y=0) and 400 churn cases (y=1). Shuffle with a declared seed, then stratify by the label into 700 training, 150 validation and 150 test rows.

The training share receives 0.60 × 700 = 420 non-churn and 0.40 × 700 = 280 churn records, so 420 + 280 = 700. Each 150-row holdout receives 90 y=0 and 60 y=1. The complete checksum is 700 + 150 + 150 = 1,000, and every split preserves the original 60:40 ratio.

Arithmetic cannot create independence. Remove exact duplicates first and choose the correct unit to split. If one customer has several sessions, all sessions for that customer must travel together, or information about that person can cross the split boundary.

Dataset split diagram showing 1,000 rows divided into train 700, validation 150, and test 150, with stratified class counts and exclusive customer assignment.

Select on validation, freeze the pipeline, then test once

Train three illustrative candidates only on the 700 training rows. With validation accuracy declared in advance as the selection metric, logistic regression with C=1 scores 123/150 = 82.0%, a decision tree with max_depth=3 scores 125/150 = 83.3%, and a gradient-boosted tree with 100 estimators and max_depth=3 scores 127/150 = 84.7%. These are teaching values, not benchmark results. The boosted candidate wins under the declared rule.

Use Model Tracking: How to Record Experiments, Metrics and Artefacts to record run lineage, artefacts and promotion gates. The data split answers a different question: which rows may fit parameters, choose settings and estimate final performance.

Now freeze the feature list, imputer, scaler, model settings, 0.50 probability threshold and metric definitions. Refit that locked pipeline on all 850 development rows, which contain 420 + 90 = 510 y=0 and 280 + 60 = 340 y=1. The 150 test rows remain untouched during fitting.

Open the test set once. The confusion matrix is:

predicted 0

predicted 1

actual 0

78

12

actual 1

12

48

Accuracy is (78 + 48) / 150 = 126/150 = 84.0%. Churn precision is 48/(48+12) = 80.0%, recall is 48/(48+12) = 80.0%, and F1 is 80.0%. The final accuracy estimate is 84.0%, not the 84.7% validation score.

Repeated test-set decisions turn test data into validation data

Continue with the same illustrative prediction file. The threshold fixed at 0.50 produces 126/150 = 84.0%. After seeing it, a developer tries 0.45 and obtains 129/150 = 86.0%, then tries 0.40 and obtains 131/150 = 87.3%. The divisions are correct, but 87.3% is not a clean final estimate. The threshold was chosen for success on those same 150 cases.

Either retain 0.50 and the original one-time estimate, or admit that the old test set has become validation data and obtain a fresh untouched holdout. Renaming the inspected file final_test.csv does not restore its role.

With limited data, reserve the same 150 final test rows and run cross-validation only inside the other 850. The protected-test boundary, not a particular splitter, is the point: fold-level preprocessing and tuning stay inside development data, the chosen pipeline is refit on all 850, and the 150 test rows are opened once. Stratify these 60:40 labels; preserve groups or time order when deployment requires them.

Parallel workflow diagram comparing clean evaluation with contaminated test reuse, including 84.0% on the first test opening and later inflated scores of 86.0% and 87.3%.

Stop leakage in preprocessing, entities and time

Preprocessing leaks when an imputer, scaler, encoder, feature selector or resampler learns from held-out rows. Fit it on training data, then apply the fitted transformation elsewhere. For training values [10,12,14,16], min-max scaling maps 10 to 0 and 16 to 1. A held-out 30 becomes (30-10)/(16-10) = 3.33. If the scaler wrongly learns from all five values, 16 becomes (16-10)/(30-10) = 0.30 and 30 becomes 1.00. The holdout has already changed the pipeline.

Identity leakage occurs when related records cross boxes. If customer C17 has five sessions, keep all five in one group split. Otherwise, customer-specific repetition can make evaluation look easier than deployment.

Time leakage occurs when a random split gives training data information from the future. If deployment predicts later cases, use chronology: the earliest 700 records train, the next 150 validate and the latest 150 test. Splitting belongs inside a complete data and modelling workflow, which readers can explore through Skill Development Courses.

Read the final score as an estimate, not a certificate

The 84.0% test accuracy still has sampling uncertainty. With p_hat = 0.84 and n = 150, a quick binomial standard error is sqrt(0.84 × 0.16 / 150) = 0.0299. A rough normal 95% interval is 0.84 ± 1.96 × 0.0299, or about 78.1% to 89.9%. This is a teaching approximation, not a guarantee of deployment performance.

When two models are compared on the same cases, Hypothesis Testing for Machine Learning: Separate Signal from Sampling Noise in Model Comparisons uses paired disagreement, effect size and multiplicity. The interval above instead quantifies uncertainty around one frozen model's test accuracy.

A useful report names the test size of 150, label balance of 90:60, threshold 0.50, confusion matrix and every metric chosen before testing. Accuracy alone hides which class is missed. If costs are asymmetric, predeclare precision, recall, F1, calibration or another relevant measure.

Sampling error is also different from distribution shift. A protected test set estimates its source population. A changed customer mix, product or collection process can change future performance, so monitor new data without retuning against the original test set.

Exams and interviews test roles, arithmetic and leakage detection

Practise with four checkable prompts:

  1. Split 800 rows by 60/20/20: 480 train, 160 validation and 160 test.

  2. Tune tree depth after each test score: the test set has become validation data.

  3. Run 5-fold cross-validation over 850 development rows: each fold has 170 validation and 680 training rows.

  4. Put one patient's visits in both train and test: this is group leakage even when row IDs differ.

Use one answer frame each time. Identify which decision used which data, state the resulting bias or leakage risk, then name the clean correction. Calculate counts, freeze decisions before testing, confine cross-validation to development data, and split by group or time when independence requires it. Write the correction in data-role terms: return to validation, freeze again, and protect a fresh test set.

Train-validation-test split: the short version and next step

Train parameters on training data. Choose settings on validation data. Lock every data and model decision. Use test data once for the final estimate. Checksum: 1,000 = 700 + 150 + 150; the validation winner is 127/150 = 84.7%, while the final test is 126/150 = 84.0% at the predeclared 0.50 threshold.

Redraw the workflow, mark where the scaler learns its minimum and maximum, then explain why 87.3% cannot be called a test estimate. If you want an optional structured next step, explore Artificial Intelligence (AI).