Model Evaluation
& Validation
Learn how to measure, test, and trust the predictions your models make: from train/test splits to cross-validation.
Why Evaluation Matters
A model that perfectly memorizes past data is useless if it fails on new data. Model evaluation answers the critical business question: "Will this model work in the real world?"
Key Vocabulary
Overfitting vs. Underfitting
The Train/Test Split
Measuring Accuracy
For classification models, accuracy is the simplest evaluation metric:
Regression: Error Metrics
For models predicting continuous values (sales, prices, scores), we measure how far off predictions are from actual values.
Two-Way vs. Three-Way Split
| Two-Way Split | Three-Way Split | |
|---|---|---|
| Sets | Train + Test | Train + Validation + Test |
| Typical Ratio | 75 / 25 | 60 / 20 / 20 |
| Tuning | No dedicated tuning set | Validation set tunes model settings |
| Best For | Simple projects, large datasets | Complex models needing parameter tuning |
Step-by-Step: Train/Test Workflow
Example: Email Spam Classifier
A company has 1,000 emails labeled as "spam" or "not spam." They split 750 for training and 250 for testing.
Example: Housing Price Model
A regression model predicts house prices. Given these test set results:
| House | Actual Price | Predicted | Error |
|---|---|---|---|
| A | $300k | $310k | $10k |
| B | $450k | $430k | $20k |
| C | $200k | $215k | $15k |
The Problem with One Split
A single train/test split is sensitive to luck. If your random split happens to put all the "easy" cases in the test set, your accuracy looks great. A different split might tell a different story.
Introducing Cross-Validation
K-Fold Cross-Validation divides the dataset into \(k\) equal parts (folds). Each fold takes a turn as the test set, while the remaining \(k-1\) folds serve as training data.
The Cross-Validation Formula
Where \(k\) is the number of folds and \(\text{Score}_i\) is the evaluation metric (accuracy, RMSE, etc.) computed on fold \(i\)'s test portion.
Example: 5-Fold CV in Action
A customer churn model is evaluated with 5-fold cross-validation. Each fold produces an accuracy score:
| Fold | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Accuracy | 85% | 82% | 88% | 84% | 86% |
Common Mistakes
Evaluation Methods Compared
| Train/Test Split | K-Fold CV | |
|---|---|---|
| Speed | Fast: train once | Slower: train \(k\) times |
| Reliability | Depends on split luck | Averages out randomness |
| Data Efficiency | 25% unused for training | Every sample tested exactly once |
| Variance | High: results change per split | Low: stable averaged estimate |
| Best For | Very large datasets (>100k rows) | Small to medium datasets |
Question 1 of 5
A model achieves 98% accuracy on training data but only 72% accuracy on the test set. What is this an example of?
Question 2 of 5
In 5-fold cross-validation, how many times is each data point used as part of the test set?
Question 3 of 5
A regression model has an RMSE of $12,000 on house price predictions. What does this tell you?
Question 4 of 5
A data scientist normalizes (scales) the entire dataset before splitting it into train and test sets. What problem does this create?
Question 5 of 5
A 5-fold CV produces accuracy scores: 88%, 91%, 85%, 90%, 86%. What is the cross-validation score?