This lesson on Train/Validation/Test — The Three-Split Discipline is hands-on and example-driven. You will learn the fundamental discipline of splitting historical data into training and testing sets for machine learning model development. This process ensures that your model is evaluated on data it has never seen, confirming its ability to generalize predictions accurately.
What You'll Be Able To Do
- Define the purpose of training data in model development.
- Explain the necessity of setting aside a test set before training begins.
- Calculate a typical 80/20 split ratio for data partitioning.
- Evaluate a model's performance using unseen data (the test set).
- Distinguish between a model that has learned specific patterns and one that generalizes well.
Topics Covered in Train/Validation/Test — The Three-Split Discipline
- Model Prediction Goal (0:00 - 0:55) — The goal is to build a model that predicts car prices based on historical features like make, age, and mileage.
- Train/Test Data Split (0:55 - 1:35) — The data must be split, typically 80% for training the model and 20% set aside for testing.
- Need for Unseen Data (1:35 - 2:10) — Testing on unseen data is necessary to ensure the model generalizes predictions rather than just memorizing the training set.
- Testing Procedure (2:10 - 2:55) — The model predicts values for the test set features without being shown the actual historical prices.
- Evaluation and Comparison (2:55 - 3:30) — Predicted values are compared against the known actual values in the test set to evaluate performance on unseen data.
- Model Approval (3:30 - 3:50) — If the model performs well on the unseen test data, it is approved because it demonstrates good generalization.
SQL Cheat Sheet
-
Historical Data— Past observations used to build predictive models, like car sales recordsSELECT make, model, age, price FROM CARS_DATA; -
Training Data— The majority of historical data used for the model to learn patternsSELECT * FROM CARS_DATA WHERE split = 'train'; -
Test Data— Unseen data reserved exclusively for evaluating final model performanceSELECT make, model, mileage FROM CARS_DATA WHERE split = 'test'; -
80/20 Split— A common rule of thumb for partitioning data into train and test setsSELECT COUNT(*) * 0.8 FROM CARS_DATA; -
Generalization— The model's ability to accurately predict outcomes on new, unseen dataSELECT price_predicted, price_actual FROM CARS_EVALUATION;
Comparison Table
| Data Set | Typical Size | Role in Modeling |
|---|---|---|
| Training Data | ~80% of total | Used to adjust model parameters |
| Test Data | ~20% of total | Used to verify generalization ability |
| Exposure to Model | Fully seen during learning | Never seen during training |
Common Pitfalls
- Mistake: Evaluating performance only on the training data used to build the model. Avoid: Always compare predicted values against actual values in the unseen test set.
- Mistake: Using the test set to adjust model hyperparameters during development. Avoid: Only use the test set once for final, unbiased evaluation.
- Mistake: Failing to separate the data before starting any model training process. Avoid: Partition the historical data into 80/20 sets immediately upon collection.
FAQs
- Why is the 80/20 split ratio used? It is a common rule of thumb, but the exact percentage depends on the model type, data size, and specific needs. The key is ensuring the test set is large enough to be representative.
- What does it mean if the model performs well on training data but poorly on test data? This indicates the model has overfit; it learned the specific patterns of the training set but cannot generalize well to new, unseen data.
- If the model performs poorly on the test set, what should I do? You should adjust the model, change the approach, or tweak the hyperparameters. You must then re-evaluate the new model using a fresh, unseen test set.