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
Total samples across classes
5000 + 3000 + 1500 + 500
= 10000
Total train samples
10000 × 80%
= 8000
Per-Class Split
| Class | Total | Train | Test |
|---|---|---|---|
| — | 5,000 | 4,000 | 1,000 |
| — | 3,000 | 2,400 | 600 |
| — | 1,500 | 1,200 | 300 |
| — | 500 | 400 | 100 |
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
- Dataset Split CalculatorCommonly used together
- Random Seed GeneratorCommonly used together
- Oversampling Ratio CalculatorCommonly used together
- Undersampling Ratio CalculatorCommonly used together
- Class Imbalance Ratio CalculatorCommonly used together
- Sequence Truncation CalculatorAlso in Miscellaneous AI