Train/Test Split Calculator

Compute train, val, and test set sizes from ratios.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Enter the number of samples and the test and validation ratios, and get the size of each split. It only calculates sizes. To split an actual CSV file, use the train-test split tool.

How to use

1
Step 1
Enter the total number of samples.
2
Step 2
Enter the test ratio and the validation ratio (0 for none).
3
Step 3
Press Calculate.

How it works

Test = round(n × test ratio) and validation = round(n × val ratio). Train is the rest. The two ratios must add up to less than 1. The result shows counts and percentages in the order train / val / test.

test = round(n·r_test);  val = round(n·r_val);  train = n − test − val

Worked example

10,000 samples

Input
n = 10,000; test ratio 0.2; validation ratio 0.1
Output
7000 / 1000 / 2000 (train / val / test)
Walkthrough
2,000 go to test, 1,000 to validation, and the remaining 7,000 are for training. With a validation ratio of 0 and n = 1,000 you get 800 / 0 / 200.

Limitations

  • Sizes only; it does not shuffle or split data.
  • No stratification advice for imbalanced classes.
  • Rounding can make the sizes differ slightly from the exact ratios on small datasets.

Questions

What is a good train/validation/test split?
70/10/20 and 80/10/10 are common. With very large data, a smaller validation and test share is fine.
How do I split an actual dataset?
Use the train-test split tool, which shuffles a CSV with a seed.
Do I need a validation set?
If you tune hyperparameters, yes, so the test set stays untouched until the end.
Why do my sizes not add up exactly to the ratios?
Counts are rounded to whole samples.

Features

  • Train, val, test sizes
  • Percentages shown
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Mean, Variance and Standard Deviation

    StatQuest with Josh Starmer

    Stats foundations behind many ML metrics tools.

    Watch on YouTube
  • TensorFlow 2.0 Complete Course

    freeCodeCamp.org

    Practical ML stack context next to AI utilities.

    Watch on YouTube
  • DeepLearning.AI

    DeepLearning.AI

    Courses and explainers for modern AI tooling.

  • Data Index

    Math is Fun

    Stats primers when reading ML evaluation outputs.