# Stratified Splits

A random split can leave more or fewer of one class in the test part than in the data, and stratify=y makes train_test_split keep each class's share the same in both parts, which you check with value_counts(normalize=True).

![Cheat sheet: Stratified Splits](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/e2d7d6349edf41b5809e9600a401054b.webp)

- Category: Machine Learning
- Level: Journeyman
- Tags: ai, python, Stratified Split, Test Data, train_test_split(), value_counts()
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/ml-stratified-splits-cheat-sheet
