Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Testing Data
Testing data is a separate set of examples that the AI model has never seen during training. It is used to measure how well the model can perform on new, real-world data.
Why We Need Testing Data
Here is a problem: if you test a model on the same data it learned from, you cannot tell if it actually learned or just memorized the answers.
Imagine a student who memorizes every answer in the textbook but cannot solve new problems on an exam. That student has not truly learned.
So in AI, we always split data into two parts:
- Training data: what the model learns from (like studying a textbook)
- Testing data: what we use to evaluate the model (like an exam with new questions)
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
The Train-Test Split
- A typical split is 80% for training and 20% for testing
- The model never sees the testing data during training
- After training, the model is tested on the held-out testing data
- The test score tells you how well the model will perform on real, new data
- If the model scores well on training data but poorly on testing data, it has memorized instead of learned
Train-Test Split in Code
# Splitting data into training and testing sets
import random
# Full dataset of student exam scores
all_data = [
([5, 70, 90], 75),
([2, 50, 60], 55),
([8, 80, 95], 88),
([1, 40, 50], 45),
([6, 75, 85], 80),
([3, 60, 70], 65),
([7, 72, 88], 78),
([4, 55, 65], 62),
([9, 85, 98], 92),
([0, 30, 40], 35),
]
# Shuffle and split 80% train, 20% test
random.shuffle(all_data)
split_index = int(len(all_data) * 0.8) # 80% for training
training_data = all_data[:split_index] # first 80%
testing_data = all_data[split_index:] # last 20%
print(f"Total examples: {len(all_data)}")
print(f"Training examples: {len(training_data)} (80%)")
print(f"Testing examples: {len(testing_data)} (20%)")
print()
print("Training data is used to LEARN")
print("Testing data is used to EVALUATE")
print()
print("The model is never allowed to see the testing data during training")Try It Yourself
Common Mistake
Warning
Never let your model see any part of the testing data during training. This is called data leakage and it will give you an overly optimistic score that does not reflect real-world performance. Always split your data before doing any processing.
Key Takeaways
- Testing data is a separate set of examples that the AI model has never seen during training.
- A typical split is 80% for training and 20% for testing
- The model never sees the testing data during training
- After training, the model is tested on the held-out testing data