liveBook · Manning

Stratified sampling

As explained in Inside Deep Learning: Math, Algorithms, Models

A sampling method that preserves class proportions across data splits or samples.

Stratified sampling creates data splits that preserve the original proportion of each class. If the dataset is 99% A and 1% B, each split aims to retain those percentages instead of allowing random variation to distort evaluation. section 4.2.1

Use it for imbalanced classification, where a model can appear accurate by predicting only the majority class. Preserving class ratios makes train/test comparisons more representative. section 4.2.1

Language classification split

For a name-language dataset, replace an unchecked random train/test split with a stratified split so every language remains represented in similar proportions. Stratified sampling is available through scikit-learn. section 4.2.1

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Defines the ratio-preservation idea and its motivation but defers detailed class-imbalance treatment and implementation.
Examples
Uses a 99%-to-1% class example and a name-language classification dataset to contrast stratified and random splits.
What it assumes
Assumes labeled classification data and explains class imbalance from the problem of uneven class ratios.
What you can do after
Apply it via scikit-learn to create train/test splits whose class percentages mirror the original dataset.
How it connects
Connects class imbalance with train/test splits, random sampling, classification accuracy, and scikit-learn.

Also explained in

Compare how 2 books explain stratified sampling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.