Beginner Topic 17 of 51 AI & Machine Learning
Cross-Validation
Rotating held-out folds to estimate generalization.
How it works
Cross-validation estimates a model's generalization performance more reliably than a single split. In k-fold cross-validation, data is divided into k parts, the model is trained on k minus 1 folds and evaluated on the remaining one, rotating until each fold has served as validation, and the scores are averaged. Variants include stratified folds to preserve class ratios, leave-one-out, grouped splits for related samples and time-series splits that respect order. Nested cross-validation separates tuning from evaluation.
Step-by-step walkthrough
- Split the data into k folds, here 4.
- Round 1: hold out fold 1 for testing, train on the rest.
- Round 2: hold out fold 2.
- Rounds 3 and 4 do the same.
- Average the scores for a stable estimate of generalization.
Where it is used
Model selection, hyperparameter tuning and comparing algorithms on small and medium datasets use it to make the most of limited data.
Common pitfall
Preprocessing such as scaling or feature selection must be done inside each fold to avoid leakage. Using random folds on temporal or grouped data leaks information and inflates results. It costs k times more training. Report mean and standard deviation, keep a final untouched test set and choose the splitting scheme that mirrors deployment.
Where it fits in the course
Cross-Validation is topic 17 of 51 in AI & Machine Learning, rated Beginner. It follows Confusion Matrix. The next topic is Gradient Descent.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the AI & Machine Learning quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the AI & Machine Learning quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Cross-Validation?
Where do people use Cross-Validation?
What is the most common mistake with Cross-Validation?
What should I learn before this topic?
How can I practice it?
Is Cross-Validation hard to learn?
How long does it take to learn Cross-Validation?
Which topics are related to Cross-Validation?
What should I study after Cross-Validation?
Related topics
- Confusion Matrix (AI & Machine Learning)
- Gradient Descent (AI & Machine Learning)
- Evaluation Metrics (AI & Machine Learning)
- Loss Functions (AI & Machine Learning)
- Cross-Platform Frameworks (Mobile, Embedded & IoT)
- Cross-Site Scripting (Security & Cryptography)