🧷  k-fold Stratified Cross-Validation (Stratified CV)

k-fold Stratified Cross-Validation (Stratified CV)#

K-fold CV that preserves class proportions in every fold.

Important

✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.

What it is#

Stratified k-fold cross-validation splits the data into k folds while preserving each class’s proportion in every fold — so a fold of a 5%-positive dataset stays about 5% positive. It combines the stability of k-fold CV with balanced folds.

Why stratify#

Plain k-fold can, by chance, build folds with too few or missing minority-class examples, giving biased or unstable metrics — especially on imbalanced data. Stratification makes each fold mirror the overall distribution, so the k scores are reliable and comparable.

How it’s used#

It is the default for classification (often repeated stratified 10-fold); scikit-learn provides StratifiedKFold. Two cautions carry over from any CV: fit preprocessing on the training folds only to avoid leakage, and don’t use it on time-series data, where time-based splits are required instead.


Theme: Validation & Cross-Validation  ·  All terminology



See also

Source article Adapted (context, re-expressed) in our own words from: k-fold Stratified Cross-Validation (Stratified CV) (insightful-data-lab.com).

Tags: purpose: reference topic: terminology level: intermediate