induwara.lk
induwara.lkAI · Machine learning

Train Test Split Calculator

Enter a dataset size and a ratio to get the exact integer sample count for train, validation, and test — or per-fold sizes for k-fold cross-validation. Counts follow scikit-learn's own rounding, so they match what your code produces. Runs fully in your browser, no signup.

By Induwara AshinsanaUpdated Jul 9, 2026
Dataset splitexact sample counts
scikit-learn convention

How many rows / examples are in your dataset.

%

Held out for final evaluation.

%

Used for tuning during training.

Train % (derived)
65%

Automatically = 100% − Test% − Validation%.

Presets

Enter a batch size to see how many mini-batches each partition needs (ceil of count ÷ batch).

Train
6,500
65% of N
Validation
1,500
15% of N
Test
2,000
20% of N
Train6,500Validation1,500Test2,000
6,500 + 1,500 + 2,000 = 10,000 — matches N (10,000) exactly.
Counts match what scikit-learn produces.

How it works

A machine-learning dataset is split into parts so a model can be trained, tuned, and evaluated on data it has not seen. The hard part is not the ratio — it is the rounding. A 15% test set of 1,003 rows is not 150.45 rows; it has to be a whole number, and different libraries round differently. This tool reproduces scikit-learn's conventions exactly so the counts you report match the counts your code produces.

Two-way split (Train / Test). Given N samples and a test fraction t, scikit-learn's train_test_split computes n_test = ceil(t × N) then n_train = N − n_test. The ceiling — not a plain round — is why a naive percentage can be off by one sample. A round-half-up option is offered for tutorials that round instead.

Three-way split (Train / Val / Test). This is done as two sequential splits, the same pattern as calling train_test_split twice. First the test set is removed: n_test = ceil(test_f × N), leaving a remainder R = N − n_test. The validation fraction is then taken relative to the remainder, val_rel = val_f / (1 − test_f), so that n_val = ceil(val_rel × R) and n_train = R − n_val. Reporting each part as count ÷ N recovers the realised percentages.

k-fold cross-validation. scikit-learn's KFold sets base = ⌊N / k⌋ and r = N mod k. The first r folds each hold base + 1 samples and the rest hold base. When a fold is used as the test set, the other k−1 folds train, so train size = N − fold size. The fold sizes always sum to N, and every sample is in the test fold exactly once — total test coverage equals N.

One subtlety this tool handles: floating-point error. In IEEE-754 doubles, 0.15 × 1000 evaluates to 150.00000000000003, and a raw ceiling would return 151 — off by one from scikit-learn. The calculator snaps any product within a tiny tolerance of a whole number back to that integer before taking the ceiling, which keeps the counts correct even for very large datasets.

Worked examples

Two-way 80/20 — N = 10,000 (scikit-learn)

  1. n_test = ceil(0.20 × 10000) = ceil(2000) = 2000
  2. n_train = 10000 − 2000 = 8000
  3. realised 8000 (80.00%) / 2000 (20.00%)
  4. check: 8000 + 2000 = 10,000 = N ✓

Three-way 70/15/15 — N = 1,000

  1. n_test = ceil(0.15 × 1000) = 150 → remainder R = 850
  2. val_rel = 0.15 / (1 − 0.15) = 0.176470…
  3. n_val = ceil(0.176470… × 850) = ceil(150) = 150
  4. n_train = 850 − 150 = 700
  5. check: 700 + 150 + 150 = 1,000 = N ✓

5-fold CV — N = 1,003 (uneven split)

  1. base = ⌊1003 / 5⌋ = 200, r = 1003 mod 5 = 3
  2. first 3 folds = 201 samples, last 2 folds = 200
  3. check: 201×3 + 200×2 = 603 + 400 = 1003 = N ✓
  4. 201-fold test → train = 802; 200-fold test → train = 803
  5. total test coverage = 1,003 (each sample tested once)

Frequently asked questions

Sources & references

The rounding conventions on this page were last cross-checked against the scikit-learn documentation on 2026-07-09. The three worked examples above are reproduced exactly by the calculator.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.