Skip to content
Calcrivo

Stratified Split Calculator

Calculate class-balanced train and test set sizes using stratified sampling.

Inputs

Total sample count for each class, separated by commas.

%

Total Train Samples

8,000

Total Test Samples

2,000

Total Samples

10,000

Step by step

  1. Total samples across classes

    5000 + 3000 + 1500 + 500

    = 10000

  2. Total train samples

    10000 × 80%

    = 8000

Per-Class Split

Per-Class Split
ClassTotalTrainTest
5,0004,0001,000
3,0002,400600
1,5001,200300
500400100

How it works

Stratified sampling applies the same train percentage independently to each class, so class_n_train = class_n_total × train%, ensuring every class contributes proportionally to both the train and test sets. This calculator accepts an arbitrary list of per-class totals and produces an exact per-class train/test split, which is the standard approach for classification tasks with multiple classes of varying size.

Formula

class_train_n = round(class_total_n × train_percent / 100)

class_total_n
Total samples for class n
train_percent
Target training set percentage

Frequently Asked Questions

Why split per-class instead of on the whole dataset at once?

Splitting the whole dataset randomly can under-represent rare classes in one partition purely by chance; splitting within each class guarantees every class is represented proportionally in both sets.

What if a class has very few samples?

For classes with fewer than ~10 samples, rounding can distort the train percentage significantly — consider merging rare classes or using leave-one-out validation instead.

Can I use this for train/val/test (three-way) splits?

Run this calculator twice: first split into train vs. (val+test), then split the (val+test) remainder again into val and test using the same method.

You might also need