Core Problem: How do we reliably estimate model performance with limited data?
Challenge: Data is precious—we need it for both training and evaluation
Goal: Unbiased estimate of model performance on unseen data
Solution: Systematically split data multiple times
Applications: Model selection, hyperparameter tuning, performance reporting
Key Insight: Cross validation provides a more robust and less biased estimate of model performance than a single train-test split
The Data Splitting Problem
Why Simple Train-Test Splits Are Insufficient
Problems with Simple Train-Test Split:
High Variance: Performance estimate depends heavily on specific split
Data Waste: Only use part of data for training
Selection Bias: May get lucky/unlucky with test set
No Hyperparameter Tuning: Can't optimize model without overfitting
Example Scenario: 1000 samples, 80-20 split
Training: 800 samples
Testing: 200 samples
What if test set is unrepresentative?
How do we tune hyperparameters?
Cross Validation Solution: Use all data for both training and validation through systematic resampling
K-Fold Cross Validation
The Standard Approach
$$CV_k = \frac{1}{k} \sum_{i=1}^k L(f^{(-i)}, D_i)$$
$$\text{where } f^{(-i)} \text{ is trained on all folds except } i$$
K-Fold Procedure:
Split: Divide dataset into k equal-sized folds
Iterate: For each fold i = 1, ..., k:
Use fold i as validation set
Use remaining k-1 folds as training set
Train model and evaluate on fold i
Average: Compute mean performance across all folds
Common Choices:
k = 5: Good bias-variance trade-off, computationally efficient
k = 10: Lower bias, higher variance, more computation
k = n (LOOCV): Lowest bias, highest variance
Cross Validation Variants
Adapting to Different Data Types
Method
Use Case
Pros
Cons
Standard k-Fold
General purpose
Balanced bias-variance
Random splits may not preserve structure
Stratified k-Fold
Classification with imbalanced classes
Preserves class distribution
Only for classification
Leave-One-Out (LOOCV)
Very small datasets
Maximum use of data
High variance, expensive
Time Series CV
Temporal data
Respects temporal order
Less data for validation
Group k-Fold
Grouped/clustered data
Avoids data leakage
Uneven fold sizes
Time Series Example: Predict stock prices
Cannot use future data to predict past
Use expanding or rolling window validation
Respect temporal dependencies
Nested Cross Validation
Unbiased Model Selection
Problem: Using cross validation for both hyperparameter tuning AND performance estimation introduces optimistic bias
Solution: Two-level cross validation
Nested CV Structure:
Outer Loop: Performance estimation (k₁ folds)
Inner Loop: Hyperparameter selection (k₂ folds)
For each outer fold i = 1, ..., k₁:
For each hyperparameter configuration h:
Inner CV score = k₂-fold CV on training data
Select best h* based on inner CV
Train model with h* on full training data
Evaluate on outer test fold i
Return: Average performance across outer folds