01 / 22

Model Evaluation
& Validation

Learn how to measure, test, and trust the predictions your models make: from train/test splits to cross-validation.

Business Analytics

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?"

✓ Good Evaluation
Tests on fresh, unseen data to estimate real performance
✕ Bad Evaluation
Tests on training data, giving a misleadingly high score

Key Vocabulary

Training Set
The portion of data used to fit (teach) the model its patterns
Test Set
The held-out portion used to evaluate how well the model generalizes
Validation Set
An optional middle set used to tune model settings before final testing

Overfitting vs. Underfitting

Underfitting Too simple: misses the real pattern Good Fit Captures the true underlying trend Overfitting Too complex: memorizes noise, fails on new data

The Train/Test Split

Full Dataset Training: 75% Test: 25% Train Model Evaluate Apply trained model to test set

Measuring Accuracy

For classification models, accuracy is the simplest evaluation metric:

Example
A model predicts 200 customer outcomes correctly out of 250 total: \(\frac{200}{250} = 0.80\) or 80% accuracy
Limitation
With imbalanced data (e.g., 95% "no fraud"), predicting "no fraud" always gives 95% accuracy but catches zero fraud

Regression: Error Metrics

For models predicting continuous values (sales, prices, scores), we measure how far off predictions are from actual values.

1
MAE (Mean Absolute Error): \(\frac{1}{n}\sum_{i=1}^{n}|y_i - \hat{y}_i|\). Average absolute gap between predicted and actual.
2
MSE (Mean Squared Error): \(\frac{1}{n}\sum_{i=1}^{n}(y_i - \hat{y}_i)^2\). Penalizes large errors more heavily.
3
RMSE (Root Mean Squared Error): \(\sqrt{\text{MSE}}\). Same units as the target, easy to interpret.

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

1
Collect & clean your full dataset. Remove duplicates, handle missing values.
2
Shuffle randomly to avoid ordering bias (e.g., dates sorted chronologically).
3
Split into training set (75%) and test set (25%).
4
Train your model using only the training set.
5
Predict on the test set and compute your evaluation metric (accuracy, RMSE, etc.).
6
Report the test score as your estimate of real-world performance.

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.

1,000 Emails 750 Train 250 Test 220 / 250 correct Accuracy = 88%

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.

Split 1 Acc = 92% Split 2 Acc = 84% Split 3 Acc = 78% Which one do you trust? Solution: Cross-Validation Systematically create multiple splits and average the results

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.

5-Fold Cross-Validation Round Fold 1 Fold 2 Fold 3 Fold 4 Fold 5 1 Test 2 Test 3 Test 4 Test 5 Test Final Score = Average of all 5 rounds

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.

\(k = 5\)
Most common choice: balances computation cost and reliability
\(k = 10\)
More reliable estimates but takes twice as long to compute
\(k = n\)
Leave-One-Out CV: extreme case, one sample as test each round

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

✕ Data Leakage
Using test data during training (e.g., scaling the entire dataset before splitting). Always split first, then preprocess each set separately.
✕ Peeking at Test Set
Repeatedly evaluating on the test set and tweaking the model. The test set must be used once at the end: no exceptions.
✕ Reporting Training Score
Claiming "99% accuracy" from training data. Always report the test or cross-validation score for honest evaluation.

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?