AI & LLMs

Cross-Validation

also: k-fold

Estimating a model’s true performance by training and testing on multiple data splits, not just one.

Cross-validation estimates how well a model will generalize by repeatedly splitting the data into training and validation folds and averaging the results — so the score does not depend on one lucky or unlucky split. K-fold splits the data into k parts, trains on k−1 and tests on the held-out one, k times.

Worked example: 5-fold cross-validation trains 5 models, each holding out a different 20% for testing, and averages their scores — a far more reliable estimate than a single 80/20 split, especially on small datasets. Gotcha: the folds must respect structure — random k-fold leaks information for time series (you would train on the future) and for grouped data (the same user in train and test), so use time-series or grouped splits there; and any preprocessing fit on the data (scaling, feature selection) must happen INSIDE each fold, or you leak and inflate the score.