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

Training Set vs Test Set

Understanding why we split data into separate training and testing subsets to evaluate model performance.

Training Set vs Test Set

What you'll learn: Why machine learning models need separate training and testing data to measure their true performance.

The Core Problem

When you build a machine learning model, you need to answer a critical question: How well will this model work on new, unseen data?

If you train a model on a dataset and then test it on that same dataset, you're essentially letting a student take a test using the exact questions they studied. They might ace it, but you won't know if they truly understand the material or just memorized answers.

The Split

This is why we divide our data into two distinct subsets:

  • Training Set: The data used to teach the model patterns, adjust weights, and optimize the objective function
  • Test Set: Fresh data the model has never seen, used only to evaluate final performance

Think of it like preparing for a real exam: you study practice problems (training set), but the actual exam has different questions (test set) that measure whether you learned general principles.

Why This Matters

Without this split, your model might achieve excellent performance during training but fail miserably in production. The model could simply memorize training examples rather than learning generalizable patterns—a problem called overfitting.

The test set gives you an honest assessment of how your model handles the real world, where it will encounter data points it's never seen before.

Key Takeaway: Splitting data into training and test sets is essential for measuring a model's ability to generalize beyond memorization—training teaches, testing evaluates true performance on unseen data.