Stratified Split Calculator
Calculate class-balanced train and test set sizes using stratified sampling.
About Stratified Split Calculator
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
Worked example
With the default values below, Stratified Split Calculator returns Total Train Samples of 8,000. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Class Counts (comma-separated)
- 5000, 3000, 1500, 500
- Train %accepts 1–99 %
- 80 %
Results
- Total Train Samples
- 8,000
- Total Test Samples
- 2,000
- Total Samples
- 10,000
Step by step
- 1Total samples across classes= 10000
- 2Total train samples= 8000
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
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.
Related Calculators
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
