← Back to list
AI & Data
#교차검증#K-Fold#과적합#하이퍼파라미터 튜닝#데이터 누수
Last updated · 2026-10-13

Cross-Validation

1. Overview

A. Definition

Cross-validation is a resampling-based validation technique that repeatedly splits the available data into multiple training/validation partitions in turn, training and evaluating the model on each, so that the estimate of generalization performance is more stable rather than depending on a single split.

The goal of a machine learning model is to work well on future data it was not trained on — that is, to generalize. But our data is finite: if we train on all of it, no sample is left to validate performance, whereas if we evaluate on a single held-out validation set (holdout), that estimate swings widely depending on which samples happened to land in the validation set. Cross-validation eases this dilemma by "recycling" the data, letting every sample serve as validation once, thereby reducing the variance of the estimate and using the data efficiently.

B. Background and Necessity

Model development is a chain of many decisions — algorithm choice, hyperparameter tuning, feature design — and comparing them objectively requires a trustworthy performance estimate. A single holdout split is simple but carries two problems. First, the smaller the data, the smaller the validation set, so the variability (variance) of the estimate grows. Second, repeatedly peeking at the same validation set to choose hyperparameters causes the model to covertly overfit that validation set, so the reported performance overstates true operational performance.

Cross-validation solves this by reusing the data for evaluation multiple times. Especially in fields where data is expensive to obtain — healthcare, manufacturing, finance — where samples may number only in the hundreds to thousands, cross-validation has become a de facto standard procedure because it provides a statistically more reliable basis for comparison on limited data. Furthermore, nested cross-validation, which separates model selection from performance reporting, structurally prevents the trap of "overfitting to the validation set."

Historically, cross-validation was established in 1970s statistics as a resampling technique for model selection and prediction-error estimation, and together with the bootstrap and jackknife it belongs to a family of methods for "estimating performance on finite samples without distributional assumptions." Today, as libraries such as scikit-learn and caret provide K-fold, stratified, and time-series splits through standard APIs, it has become a common language that every data analyst applies by default. In short, cross-validation is the most universal and proven procedure for answering the question "can I trust this model?"

C. Characteristics

  • Reusability: every sample is used alternately for training and validation, giving high data-utilization efficiency.
  • Variance reduction: averaging performance over multiple splits makes the estimate more stable than a single split.
  • Bias-variance trade-off: the number of splits (k) and the validation-set size trade off the bias and variance of the estimate.
  • Dependence on conditions: for time-series, grouped, or imbalanced data, a naive random split distorts performance, so variant techniques are needed.

2. Principles and Overall Structure of Cross-Validation

Cross-validation branches into several variants depending on "how the data is split and recycled." The structure diagram below organizes the representative techniques by splitting method and data characteristics.

flowchart TB
  CV["Cross-Validation"] --> H["Simple split<br/>Holdout"]
  CV --> K["Repeated split<br/>K-Fold family"]
  CV --> N["Model-selection separated<br/>Nested CV"]
  K --> KF["Basic K-Fold"]
  K --> SK["Stratified K-Fold"]
  K --> LOO["LOOCV<br/>(k=N)"]
  K --> RP["Repeated K-Fold"]
  CV --> S["Data-specific variants"]
  S --> TS["Time series<br/>TimeSeriesSplit"]
  S --> GP["Grouped<br/>GroupKFold"]
  style CV fill:#e8f0fe,stroke:#2f6fed,stroke-width:2px
  style S fill:#fef3e8,stroke:#ed922f,stroke-width:1px

The core principle running through cross-validation is the bias-variance trade-off. Carving off a large validation set (making the training set small) means the model learns too little and the performance is estimated with a downward bias, whereas carving off a small validation set increases the variance of the estimate. Raising the number of splits k makes each round's training set closer to the whole, reducing bias, but because the splits share much of their training data, the performance estimates become correlated, so the variance-reduction benefit is limited while only the compute cost grows. For this reason, k=5 or k=10 is used in practice as a rule-of-thumb balance point of bias, variance, and cost.

Another principle is information isolation. The validation set must mimic a "never-before-seen future," so the statistics of preprocessing (normalization, missing-value imputation, feature selection) must be computed only from the training fold and then applied to the validation fold. If this isolation breaks, information from the validation set leaks into training — data leakage — and the trust that cross-validation provides becomes an illusion.

3. Major Techniques and Procedure

The process diagram below shows one round of the most widely used K-fold cross-validation together with the flow of nested cross-validation, which also includes hyperparameter tuning.

flowchart LR
  subgraph OUTER["Outer loop — performance estimation"]
    D["Full dataset"] --> SP["Split into K folds"]
    SP --> TR["K-1 = training folds"]
    SP --> VA["1 = validation fold"]
    TR --> FIT["Train model<br/>(preprocessing fit on training fold only)"]
    FIT --> EV["Evaluate on validation fold"]
    EV --> AVG["After K rounds, average and std dev of performance"]
  end
  subgraph INNER["Inner loop — hyperparameter selection"]
    TR --> HP["Re-split training fold into K' folds"]
    HP --> GRID["Hyperparameter search"]
    GRID --> BEST["Select best value"]
    BEST --> FIT
  end
  style OUTER fill:#e8f0fe,stroke:#2f6fed,stroke-width:1px
  style INNER fill:#eafbea,stroke:#2faf5a,stroke-width:1px

A. Holdout

The simplest method splits the data once, typically into 70-80% training and 20-30% validation, and evaluates. Because the computation happens only once it is fast and easy to implement, and on large datasets of hundreds of thousands of records or more, split variability is small enough to be sufficiently reliable. In fact, in ImageNet-scale large-scale deep learning, the repeated-training cost of cross-validation is enormous, so a fixed train/validation/test (holdout) split is common.

However, holdout is fatal when data is scarce. The performance estimate sloshes by several percentage points depending on which samples happen to cluster in the validation set. For example, even if one holdout run on 500 medical records yields 82% accuracy, changing the split seed can produce 76% or 88%, making it risky as a basis for model comparison.

Holdout also splits the data once into "what to train on" and "what to validate on," so the 20-30% used for validation contributes nothing to training. In a situation where data is precious, this waste directly lowers model quality.

B. K-Fold Cross-Validation

K-fold cross-validation divides the data into k folds, then uses each fold once as the validation set and the remaining k-1 as the training set, so it repeats training and evaluation k times in total and averages the performance. Every sample is used for validation exactly once, so no data is discarded, and from the k performance values one can report both the mean and standard deviation, judging simultaneously "how good this model is on average, and how stable it is."

The choice of k is a trade-off of bias, variance, and cost. A small k (e.g., k=3) makes the training set small, biasing performance pessimistically, while a large k (e.g., k=20) brings the training set close to the whole but makes the folds share much training data, correlating the estimates and requiring 20 training runs, so cost surges. Most practice therefore adopts k=5 (about 20% validation) or k=10 (about 10% validation) as this balance point.

Number of splits k Training-set share per round Estimate bias Estimate variance Compute cost
k=2-3 50-67% Large (pessimistic) Small Low
k=5 80% Moderate Moderate Moderate
k=10 90% Small Moderate High
k=N (LOOCV) ≈100% Nearly none Large Very high

As the table shows, raising k does not improve things unconditionally; going to the extreme like LOOCV eliminates bias but explodes variance and cost. In other words, it is not a problem of "just maximize one metric" but a design decision that weighs data size and compute budget together.

Another practical value of K-fold is that it can report the uncertainty of performance together. For example, if model A is "mean accuracy 84%, std dev 2%p" and model B is "mean 85%, std dev 9%p," B looks better by the mean alone, but B's performance swings widely across splits and may be risky in operation. Cross-validation thus presents mean and variability at once, providing grounds for choosing "the more stable model even if its mean is slightly lower." This is information a single holdout can never give.

C. Stratified, LOOCV, and Repeated Cross-Validation

Stratified K-Fold uses stratified sampling so that each fold preserves the class ratio of the whole. In classification problems — especially imbalanced data where positives are only 5% — a naive random split can leave some folds with almost no positives, rendering evaluation meaningless; stratified splitting distributes positives evenly across all folds, preventing this distortion. It is effectively the default in classification.

LOOCV (Leave-One-Out) is the extreme of k=N: it leaves just one sample as the validation set, trains on all the rest, and repeats this N times. Because the training set is almost the whole, the bias of the performance estimate is smallest, but it must train N times, so cost is unrealistic once data reaches even a few thousand records, and it has the weakness of large variance in the estimate. LOOCV is therefore used in limited cases where samples number only in the tens to hundreds.

Repeated K-Fold shuffles the folds differently each time, repeats the entire K-fold several times, and averages the results. It is used when one wants to further reduce the influence of a "lucky/unlucky split" that can arise in a single K-fold, lowering the variance of the estimate further on small data.

The effect of stratified splitting is clear in numbers. Suppose 1,000 fraud-detection records with 3% positives are split into 5 folds: with a naive random split the number of positives per fold is erratic — as many as 14 or as few as 3 — so in some folds recall essentially cannot even be measured. In contrast, stratified splitting places about 6 positives in every fold, reducing the inter-fold performance variance itself and making evaluation fair. The scarcer the minority class, the more decisive this difference becomes.

D. Nested Cross-Validation

If hyperparameter tuning and performance reporting use the same validation set, the model is selected to fit that validation set, so the reported performance is optimistically inflated. Nested cross-validation prevents this by using two loops. In the inner loop, only the training fold is re-split to choose hyperparameters, and in the outer loop that entire selection process is treated as a single "model" and evaluated on an outer validation fold never seen before. This way, the generalization performance of "the whole pipeline including tuning" can be estimated without bias.

Nested cross-validation increases compute by the product of the outer and inner split counts (e.g., 5×5 = 25× training), but in exchange it guarantees trust in situations requiring rigorous reporting of model comparison, such as papers, review, or regulatory submission. It is especially recommended in bio/medical fields where data is scarce and overfitting risk is high.

The key insight nested cross-validation reveals is that "hyperparameter search is itself a learning process." If one picks among hundreds of hyperparameter combinations by validation-set score, the combination with the highest score may be a result that optimized not only skill but also luck (noise). For example, it is common for cross-validation accuracy measured non-nested to be 90% but drop to 86% when re-measured in the nested way, and this 4%p gap is precisely the magnitude of "overfitting to the validation set." Since deployment to operation ends up showing performance near 86%, nested validation can be called a device that surfaces post-deployment performance shock in advance.

4. Cross-Validation for Special Situations and Data Leakage Prevention

The trust that cross-validation provides rests on the premise that "the validation set correctly mimics future data." The representative situations where this premise breaks are time-series and group-structured data, and using a naive random K-fold here severely overestimates performance.

Time-series cross-validation must forbid training on the future and evaluating on the past. Using a random split mixes future points into training, creating leakage of "knowing the future and predicting the past." Instead, one uses forward chaining that respects time order — train on the past → evaluate on the immediately following interval — as in TimeSeriesSplit. For instance, a demand-forecasting model might show 6% MAPE under random K-fold but 11% under time-ordered forward validation, with the former greatly overestimating operational performance — a common occurrence.

Group cross-validation (GroupKFold) splits by group so that multiple samples from the same entity (patient, user, factory equipment) do not enter training and validation simultaneously. If several CT images of the same patient are split across training and validation, the model memorizes "that patient" rather than the "disease," so validation accuracy looks like 95% but plunges to the 70s on new patients — this kind of leakage occurs. Group splitting structurally blocks it.

Data leakage prevention is a common rule of all cross-validation, beyond special situations. Preprocessing such as normalization, missing-value imputation, feature selection, and oversampling (SMOTE) must be fit only on each round's training fold and merely transform-applied to the validation fold. A common mistake is to scale the whole data once and then run cross-validation; this leaks the validation fold's distribution information into training through preprocessing, inflating performance. Wrapping preprocessing and the model together as one with scikit-learn's Pipeline and feeding it into cross-validation guarantees this isolation automatically.

In particular, the leakage of performing feature selection outside cross-validation first is fatal. If one picks the top features highly correlated with the target on the whole data and then runs cross-validation only on those features, the feature-selection step has already peeked at the validation fold's answers, so even meaningless random features can produce a plausible-looking 70-80% cross-validation accuracy as an illusion. The correct procedure is to put feature selection inside each fold's training data and repeat it within the cross-validation loop. Any performance report that ignores this principle invariably collapses at the reproduction stage.

5. Deep Dive — Recent Trends and Practical Application

Combination with AutoML and hyperparameter optimization: automation tools such as Optuna and Auto-sklearn internally use the cross-validation score as the objective function to search hyperparameters. If the search chases the cross-validation score excessively, meta-overfitting to the validation set arises, so the final performance must always be confirmed on a separate test set not used in the search, or by nested cross-validation.

Realistic compromise in large-scale deep learning: when a single training run takes days to weeks, as in LLMs and vision foundation models, k-fold repetition is practically impossible. In this domain a fixed holdout (train/validation/test) split is used, and trust is instead secured by the fact that the data scale is large so the variance of a single split is small. That is, cross-validation is more valuable the smaller the data, and more replaced by holdout the larger it is — a clear tendency.

Statistical significance of model comparison: to judge whether the difference in cross-validation mean performance between two models is "chance or real," statistical testing beyond a simple mean comparison is needed. However, because the fold performances of cross-validation share training data and are therefore not independent, an ordinary t-test inflates the Type I error. A corrected resampled t-test or a test based on repeated cross-validation is recommended. This is worth understanding in connection with [[clt-t-z-test]] as a practical response to when its assumption (independence) breaks.

Validation in the era of distribution change (drift): when the data distribution of the operating environment changes over time, cross-validation performance measured on past data does not guarantee the future. Therefore cross-validation does not end as "one validation before deployment"; combined with post-deployment [[data-quality-management]] and monitoring, it is trending toward becoming part of the MLOps lifecycle that revalidates periodically.

Extension to adversarial and fairness perspectives: recently there is a strong current to measure not only mean performance but also per-group (gender, age, region) performance gaps during cross-validation to check fairness. For example, if one stratifies by group and aggregates each group's recall gap per fold, a model whose overall accuracy is high but whose performance plunges only for a specific minority group can be filtered out before deployment. This touches the "per-group performance evaluation" that regulations such as the EU AI Act require, showing that cross-validation is expanding beyond mere performance estimation into a verification tool for responsible AI.

6. Considerations and Implications

From a professional engineer's perspective, cross-validation is not merely a statistical technique but a design activity for making trustworthy decisions on limited data. The following must be considered comprehensively in technique selection and operation.

  1. Strategy separated by data scale: for small data of hundreds to thousands of records, reduce variance with K-fold / repeated cross-validation; for large-scale, high-cost training (deep learning) of hundreds of thousands or more, control cost with a fixed holdout — a compromise matched to scale is key.
  2. Technique choice matched to data structure (trade-off): classification imbalance calls for stratified K-fold, time series for forward validation, and repeated measurements / entity overlap for group splitting; a random split that ignores these overestimates performance and leads to operational incidents.
  3. Institutionalize leakage blocking as a pipeline: do not leave to individual care the rule of confining preprocessing statistics-fitting to the training fold; structurally enforce it with Pipeline, feature stores, and validation automation to secure reproducibility and trust.
  4. Separate model selection from performance reporting: to avoid reporting final performance on the validation set used for tuning, place nested cross-validation or a separate test set to remove optimistic bias, applying it strictly the more the model is subject to regulation and audit.
  5. Balance of cost and trust, and outlook: k, the number of repetitions, and whether to nest are all exchanges of compute cost for estimate trust, so design them to match the task's risk level (the higher the risk — healthcare, finance — the stricter). Going forward, combining with AutoML and distributed-training infrastructure to internalize cross-validation into the pipeline, and extending to continuous validation that responds to distribution change, is the likely direction.

References


In one line: Cross-validation is a technique that recycles data into multiple training/validation splits to estimate generalization performance stably; it sets k by the bias-variance-cost trade-off (typically 5-10), and through variants matched to data structure (imbalance, time series, groups) and through leakage blocking and nested validation, it provides a trustworthy basis for model selection.