AI engineering glossary · ML fundamentals
What is CV (cross-validation)?
Cross-validation (also called CV, Rotation estimation): A way of estimating how well a model will perform on new data by repeatedly splitting the data, training on some parts and testing on the remaining part, then averaging the results. It uses all the data for both purposes and is more reliable than one split, especially for small datasets.
Cross-validation: an example
Rather than one 80/20 split, you train five times, each time testing on a different fifth of the data, and average the five scores.
Cross-validation in Python
A short example you can run (Python 3.11, scikit-learn). The output below is what it really prints.
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score
X, y = load_iris(return_X_y=True)
scores = cross_val_score(LogisticRegression(max_iter=1000), X, y, cv=5)
print("fold scores:", scores.round(3))
print("mean:", scores.mean().round(3), "+/-", scores.std().round(3))Output
fold scores: [0.967 1. 0.933 0.967 1. ] mean: 0.973 +/- 0.025
Related terms
More ML fundamentals terms
- Curse of dimensionality
- Data leakage
- Data snooping
- Data-centric AI
- Dataset
- Decision threshold
- Discriminative model
- Distribution shift
Where you learn it
Cross-validation is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.