Choose the right CV method for your medical machine learning project. Follow our interactive decision tree or consult the detailed method matrix.
Start with the data type question and follow the branches to find the best CV method for your use case.
A comprehensive reference of all cross-validation methods, organized by data type and use case.
| Data Characteristic | Sample Size | Primary Goal | Recommended Method | Why? |
|---|---|---|---|---|
| I.I.D. Data | ||||
| Independent samples | >1000 | Quick evaluation | Hold-Out (70/30) | Fast, simple |
| Independent samples | 100 - 1000 | Robust evaluation | 5-Fold CV | Good bias-variance tradeoff |
| Independent samples | <100 | Max data usage | LOOCV | Uses all data for training |
| Imbalanced classes | Any | Maintain class ratio | Stratified k-Fold | Preserves class distribution |
| Independent samples | Any | Confidence intervals | Bootstrap .632 | Provides CI estimates |
| Independent samples | Any | Model selection | Nested CV | Unbiased hyperparameter tuning |
| Temporal Data | ||||
| Time series | Any | Forecasting | Time Series Split | Respects temporal order |
| Time series | Long series | Fixed window | Rolling Window | Constant training size |
| Time series | Growing data | Use all history | Expanding Window | Increasing training data |
| Time series | With patterns | Preserve patterns | Blocked Time Series | Maintains temporal blocks |
| Financial / Trading | Any | Prevent leakage | Purged K-Fold | Adds temporal gaps |
| Grouped Data | ||||
| Patient records | Many groups | Standard validation | Group k-Fold | No patient in multiple folds |
| Patient records | Few groups | Test generalization | Leave-One-Group-Out | Each group as test |
| Hierarchical | Multi-level | Respect hierarchy | Hierarchical Group CV | Maintains structure |
| Imbalanced groups | Any | Balance + grouping | Stratified Group k-Fold | Preserves both constraints |
| Spatial Data | ||||
| Geographic | Grid-based | Prevent leakage | Buffered Spatial CV | Adds buffer zones |
| Geographic | Continuous | Standard spatial | Spatial Block CV | Creates spatial blocks |
| Spatiotemporal | Both dimensions | Complex patterns | Spatiotemporal Block | Handles both aspects |
| Environmental health | Geographic + health | Environmental factors | Environmental Health CV | Epidemiology studies |
| Additional Methods | ||||
| Independent samples | <50 | Exhaustive validation | LPOCV (Leave-p-Out) | Tests all p-combinations |
| Independent samples | Any | Multiple random splits | Monte Carlo CV | Flexible, confidence intervals |
| Time series | Complex patterns | Multiple test periods | Combinatorial Purged CV | Financial / trading data |
| Time + Groups | Both constraints | Combined validation | Purged Group Time Series | Complex medical studies |
| Time series | Nested optimization | Temporal + hyperparam | Nested Temporal CV | Advanced forecasting |
| Grouped data | Test on p groups | Multiple group testing | Leave-p-Groups-Out | Multi-site validation |
| Grouped data | Multiple runs | Robust group validation | Repeated Group k-Fold | Stable estimates |
| Hierarchical | Multiple levels | Respect all levels | Multi-level CV | Hospital > Dept > Patient |
| Grouped data | Hyperparam tuning | Nested + grouped | Nested Grouped CV | Unbiased selection |
Real-world medical ML scenarios with recommended CV methods and ready-to-use code examples.
from trustcv.splitters.grouped import GroupKFoldMedical
cv = GroupKFoldMedical(n_splits=5)
for train, test in cv.split(X, y, groups=site_ids):
# No site appears in both train and test
from trustcv.splitters.temporal import TimeSeriesSplit
cv = TimeSeriesSplit(n_splits=5)
for train, test in cv.split(X):
# Always train on past, test on future
from trustcv.splitters.iid import StratifiedKFoldMedical
cv = StratifiedKFoldMedical(n_splits=5)
for train, test in cv.split(X, y):
# Maintains class balance across folds
from trustcv.splitters.temporal import PurgedGroupTimeSeriesSplit
cv = PurgedGroupTimeSeriesSplit(n_splits=5, purge_gap=30) # 30-day gap
for train, test in cv.split(X, y, groups=patient_ids, times=visit_dates):
# Respects both patient grouping and temporal order
from trustcv.splitters.spatial import BufferedSpatialCV
cv = BufferedSpatialCV(n_splits=5, buffer_size=10) # 10km buffer
for train, test in cv.split(X, coordinates=gps_coords):
# Buffer prevents spatial leakage
Common pitfalls and best practices to ensure valid cross-validation results.
Compare trade-offs between variance, bias, and computational requirements.
| Method | Computational Cost | Variance | Bias | Use When |
|---|---|---|---|---|
| Hold-Out | Fastest | High | Low | Large datasets, quick tests |
| 5-Fold CV | Medium | Low | Standard choice | |
| 10-Fold CV | Low | Low | Need lower variance | |
| LOOCV | Slowest | Lowest | Low | Small datasets |
| Bootstrap | Low | Medium | Need confidence intervals | |
| Nested CV | Low | Lowest | Hyperparameter tuning | |
| Group k-Fold | Medium | Low | Grouped data | |
| Time Series Split | Medium | Low | Temporal data |
Quick reference guidelines for choosing folds, methods, and handling special cases.