Machine Learning
Intermediate
4.5
Cross-Validation Explained
Get a stabler estimate of performance than a single train/test split.
0h 20m
1 lesson
1.2K students
What You'll Learn
Learning objectives will be added soon.
Tutorial Content
Why one split isn't enough
A single test split can be lucky or unlucky. k-fold cross-validation splits data into k parts, trains on k−1 and tests on the remaining fold, then rotates — averaging the scores.
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5, scoring="f1")
print(scores.mean(), "+/-", scores.std())When to use which
- k-fold for most cases (k=5 or 10).
- Stratified k-fold for imbalanced classification (keeps class ratios).
- TimeSeriesSplit for temporal data — never shuffle time.
Report the mean and the spread; a high average with huge variance isn't reliable.
Your Progress
Sign in to track your progress
Tags
Machine Learning
Evaluation
scikit-learn