Loading…
Glossary term
A technique that evaluates a model by training and testing it on several different splits of the data.
Cross-validation splits the data into several folds. The model is trained on all but one fold and tested on the held-out one, repeating until every fold has been the test fold. The scores are then averaged.
It gives a steadier estimate than a single split, which matters when data is limited.
| Fold 1 | Fold 2 | Fold 3 | Fold 4 | Fold 5 | |
|---|---|---|---|---|---|
| Round 1 | TEST | train | train | train | train |
| Round 2 | train | TEST | train | train | train |
| Round 3 | train | train | TEST | train | train |
Cross-validate with scikit-learn
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5)
print(scores.mean())It is a standard way to compare models fairly on small datasets.