Test Data

What Is Test Data?

Test data is a portion of the dataset that is held out and used only at the very end to evaluate the final performance of a trained model. It represents examples the model has never seen during training or development.

Three Data Roles

Training Data — Used to teach the model

Validation Data — Used during development to tune and select models

Test Data — Used once at the very end for final evaluation

Why Test Data Matters

Test data gives an unbiased estimate of how the model will perform on new data in the real world.

The Final Exam Analogy

Flashcards — Training data

Practice tests during studying — Validation data

The actual exam — Test data (taken only once at the end)

Test Data in Action

Email Classification Test

Test email — "Limited time offer — click here now!"

Model prediction — Spam

True label — Spam

After testing 10,000 emails: 9,600 correct → Test Accuracy = 96%

Machine Learning Workflow

01

Collect all available data

02

Split into training (70%), validation (15%), and test (15%) sets

03

Train the model on training data only

04

Evaluate on validation data and tune the model

05

Select the best model version

06

Evaluate the final model on test data once

07

Report the test performance as the real-world estimate

Data Split Example

10,000 Examples Total

Training: 7,000 (70%) — Largest share; model needs many examples to learn

Validation: 1,500 (15%) — Used to tune the model during development

Test: 1,500 (15%) — Held until the very final evaluation

The Problem of Repeated Test Use

Bad Practice

Use the test set to tune the model, then evaluate on the same test set.

Problem — The model was indirectly fitted to the test data. The evaluation is no longer honest.

Good Practice

Use validation data for all tuning decisions.

Use test data only once at the final evaluation.

Measuring Generalization

Good Generalization

Training: 92%

Validation: 90%

Test: 89%

Small differences — the model learned real patterns

Poor Generalization

Training: 99%

Validation: 76%

Test: 72%

Large gap — the model memorized training data

Overfitting and Underfitting on Test Data

Overfitting

Training accuracy: 99% | Test accuracy: 70%

The model performs well only on data it has already seen — it memorized instead of learning.

Underfitting

Training accuracy: 58% | Test accuracy: 56%

The model performs poorly even on training data — it has not learned enough.

Training Data vs Validation Data vs Test Data

Data SplitWhen UsedPurposeHow Often Used
TrainingDuring trainingTeach the modelEvery epoch
ValidationDuring developmentTune and select modelsMany times
TestAfter trainingFinal evaluationOnce only

Evaluation Metrics for Test Data

Problem TypeCommon Metrics
ClassificationAccuracy, Precision, Recall, F1 Score
RegressionMAE, MSE, RMSE, R²
Object DetectionmAP, IoU
NLPAccuracy, BLEU, Perplexity
Classification Example — Spam Detection

Accuracy: 92% | Precision: 88% | Recall: 95% | F1 Score: 91%

Regression Example — House Prices

MAE: $20,000 — On average, predictions are off by $20,000

Why Test Data Must Be Representative

Self-Driving Car Example

Trained and tested only on sunny highway roads.

Real-world conditions also include rain, snow, city streets, and night driving.

Problem — The model passes the test but may fail in real deployment

Voice Assistant Test Data Should Include
  • Multiple languages
  • Multiple accents
  • Background noise conditions
  • Different age groups

Test Set Size Matters

Too Small (10 examples)

One or two errors can change accuracy by 10–20%.

Results are unreliable and may not reflect real performance.

Larger (10,000 examples)

Each error only changes accuracy by 0.01%.

Results are more stable and reliable.

Data Leakage in Test Data

Bad Approach

Apply normalization using statistics from the entire dataset before splitting.

Test data statistics influenced training — leakage.

Better Approach

Split the data first. Calculate preprocessing statistics using only training data. Apply those same statistics to the test set.

Test Data vs Production Data

Data Drift Example

A fraud detection model trained in 2020 performs well on its 2020 test set.

By 2023, new fraud tactics have emerged that the model has never seen.

Result — Test accuracy from 2020 no longer reflects current performance

Models should be monitored in production and retrained when drift is detected.

Common Mistakes

Mistakes to Avoid
  • Using the test set multiple times during development
  • Splitting the data after applying preprocessing (causes leakage)
  • Using a test set that is too small or not representative
  • Treating test accuracy as the only measure of performance
  • Failing to monitor models after deployment for data drift

Good Test Data

Characteristics
  • Properly held out from all training and tuning
  • Representative of real-world conditions
  • Large enough for statistically meaningful results
  • Used only once — never during training or development
  • Includes diverse examples across all relevant groups

Real-World Examples

Spam Detection

Training: 7,000 | Validation: 1,500 | Test: 1,500

Test accuracy: 93% — correctly classifies 93% of emails it has never seen

Medical Diagnosis

Training: 8,000 | Validation: 1,000 | Test: 1,000

Results must be reported separately per patient group to check for fairness and bias

House Price Prediction

Training: 7,000 | Test: 1,500

Test MAE: $25,000 — on average, predictions are $25,000 off on unseen houses

Key Takeaways

Summary
  • Test data is held out until the very end for a final, unbiased evaluation
  • Test data must not be used during training or tuning
  • Test performance estimates how the model will perform in the real world
  • Good generalization means small differences between training, validation, and test accuracy
  • Overfitting produces high training accuracy but low test accuracy
  • Representative and sufficiently large test sets are essential
  • Models should be monitored in production because real-world data can change

Need Help?

Ask the AI if you need help understanding test data, data splitting, how to measure generalization, evaluation metrics, or the problem of data leakage in test sets.