Never trust a model evaluated only on its training data. Use cross-validation (like K-Fold or Stratified K-Fold for imbalanced data) to get a realistic estimate of how your model will perform in the real world.
π This post is part of the "Machine Learning" series
Cross-Validation in Machine Learning: Why It Matters
In machine learning, building a model that performs perfectly on your training data is relatively easy. The real challenge is ensuring that the model performs just as well on data it has never seen before. If you donβt evaluate this properly, you risk deploying an overfitted model that fails spectacularly in production.
Cross-validation is a model-validation technique that estimates how well a machine learning model generalises to unseen data by repeatedly splitting the dataset into training and validation subsets. It is the gold standard for assessing generalisation.
In this post, we will explore the concept of generalisation and implement various cross-validation techniques using the Titanic dataset and The Daily Minimum Temperatures dataset (for time series splits). All implementations will use scikit-learn.
Still in this guide
Prerequisites: Python Libraries for Cross-Validation
Understanding Generalisation in Machine Learning
What Is Cross-Validation?
The Main Purpose of Cross-Validation
Cross-Validation and the Bias-Variance Tradeoff
Learning Curves in scikit-learn
Different Cross-Validation Techniques
Speeding Up scikit-learn with Intel's Extension
Further Reading on Cross-Validation
Cross-Validation Best Practices
Conclusion: Choosing the Right Cross-Validation Technique
References
You've hit a Deep Dive tutorial.
I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):
Full content temporarily unavailable β refresh in a moment
You're in
I'll send weekly notes on AI tools, Python, and what I'm actually building. Check your inbox for Set a password to unlock articles β the form does not log you in.
New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in β use the same email afterwards.
References
About Elena
Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.
Citation
Elena Daehnhardt. (2025) 'Cross-Validation Techniques', daehnhardt.com, 13 March 2025. Available at: https://daehnhardt.com/blog/2025/03/13/cross-validation/
Want the Python virtual environments cheat sheet and the Python errors and logging cheat sheet in your inbox?
Python Virtual EnvironmentsPython Errors & LoggingFantastic AI: The 2026 Toolkit
+4more free gifts
You're in
I'll send weekly notes on AI tools, Python, and what I'm actually building. Check your inbox for Set a password to unlock articles β the form does not log you in.