Course contentsShow
← Computer Science
Lesson 2777 of 2,87262. Machine Learning FundamentalsFree lesson

Training Data vs Test Data

The fundamental split between data used for learning and data used for evaluation, and why this separation is critical.

Training Data vs Test Data

You'll learn why machine learning models require two separate datasets and why mixing them up undermines everything.

The Fundamental Split

In machine learning, we divide our data into two distinct sets:

  • Training data: The dataset the model learns from. The algorithm examines these examples, identifies patterns, and adjusts its internal parameters to minimize errors on this data.
  • Test data: A completely separate dataset held back during training. After the model is trained, we evaluate it on this unseen data to measure how well it generalizes.

Why This Separation is Critical

Think of training data like practice exams a student studies from, while test data is the real final exam with new questions. If the student memorized answers to the practice problems, we'd never know if they truly understood the material or just memorized specifics.

Similarly, if we train and test on the same data, the model might achieve perfect accuracy by simply memorizing the training examples rather than learning generalizable patterns. This is called overfitting. The test set reveals whether the model learned real patterns (high test accuracy) or just memorized training examples (low test accuracy despite high training accuracy).

The Golden Rule

Never let your model see the test data during training. Test data must remain completely hidden until after all training decisions are finalized. Once you peek at test performance and adjust your model, that data is "contaminated" and no longer provides an honest assessment of generalization.

Key Takeaway: Training data teaches the model; test data honestly evaluates whether it learned generalizable patterns or just memorized specifics. This separation is fundamental to trustworthy machine learning.