# Cross-Validation

> Source: https://modeladay.com/models/cross-validation/
> Category: principle | Topics: science, decision, systems | Difficulty: 3/5

## Definition

Divide data into folds. Hold out one fold per round, refit on the rest and combine errors on cases unseen during that fit. When predicting for new stores, machines or people, keep related records in the same fold.

## Core Rule

Divide data into folds. Hold out one fold per round, refit on the rest and combine errors on cases unseen during that fit. When predicting for new stores, machines or people, keep related records in the same fold.

## Opening Context

Imagine a repair team taking five photos apiece of forty machines. They want a model that can look at a photo and tell whether the wiring has come loose. It gets ninety-five percent right in testing, so the team puts it to work on a newly arrived batch.

On those machines, the model gets the wiring wrong again and again. The team has to go back and find out what it did to earn that score.

This is where cross-validation comes in. You split your data into parts, take turns testing on one part, and train on the rest each time. Then you combine the scores. Let's follow the team through a second exam and see what that tells you about setting one up yourself.

## How It Works (Preview)

Start with how they might set the exam. Suppose they divide the photos into five parts, called folds. In the first round, one fold sits out for the test while they train on the other four. Then the second fold sits out, and they train a fresh model.

By the time they finish the rotation, each photo has appeared on the test exactly once. The errors from all those rounds give them an estimate of how the model will do on new data.

## When It Fails (Preview)

There are still ways to set a bad exam. The first comes up when you're trying to predict the future.

## Full Lesson, Audio & Practice

Get the full Cross-Validation breakdown, 5-minute audio lesson, interactive mechanism animation, and decision checklist in the ConceptFlow app:
- iOS App Store: https://apps.apple.com/app/conceptflow-mental-models/id6756862333
- Google Play: https://play.google.com/store/apps/details?id=com.juxianyp.conceptflow
- Web page: https://modeladay.com/models/cross-validation/

## Related Mental Models

- [Overfitting](https://modeladay.com/models/overfitting/)
- [Rolling-Origin Evaluation](https://modeladay.com/models/rolling-origin-evaluation/)
- [Bias–Variance Tradeoff](https://modeladay.com/models/bias-variance-tradeoff/)
