Train/Test Split

Paste a CSV and split its data rows into train and test sets — plus an optional validation set. Stratify on a label column to keep class balance, group rows so related records can't leak across splits, or turn shuffling off for a time-series split. Every draw is reproducible from the seed.

Try:
Splits

About this tool

Use this browser-local CSV splitter to create reproducible train, test and optional validation sets for machine-learning experiments. Paste a CSV, choose a test size as either a fraction (0.2) or an absolute row count (50), and the tool returns labelled CSV sections, one selected split, a summary table, or JSON containing every split.

The default is an 80/20 train/test split with seed = 42, so the same CSV and settings always produce the same rows. Rows keep their original order inside each output split, which makes the result easier to inspect and diff.

You can stratify on a label column to keep class balance across splits, quantile-bin a numeric stratification column, group related rows so they never leak across train and test, or turn shuffling off for a sequential time-series split where the newest rows land in the test set.

Worked example

Input:

id,label
1,a
2,b
3,a
4,b
5,a
6,b
7,a
8,b
9,a
10,b

With test_size = 0.2, validation_size = 0, shuffle = false, and output = sections, the rows are split sequentially:

# train (8 rows)
id,label
1,a
2,b
3,a
4,b
5,a
6,b
7,a
8,b

# test (2 rows)
id,label
9,a
10,b

For a stratified split, keep shuffle on and set stratify_column = label. For a leakage-safe grouped split, leave stratify_column empty and set group_column to a patient, user, document, or other group identifier.

Limits and edge cases

FAQ

Should I enter `0.2` or `20` for a 20% test split?

Use 0.2. Numbers below 1 are treated as fractions of the data rows. A value of 20 means exactly twenty rows, not twenty percent.

How do I make the split reproducible?

Keep the same input CSV, the same settings, and the same seed. The default seed is 42, so results are reproducible even if you never change the seed field.

When should I use stratify instead of group?

Use stratify_column when you want each split to preserve a label distribution, such as positive and negative classes. Use group_column when related rows must stay together, such as visits from the same patient or records from the same user. The tool requires you to choose one because the semantics are different.

How do I split time-series data?

Turn shuffle off. The tool then uses a sequential split: training rows come first, optional validation rows follow, and the test set gets the last rows.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool train-test-split "id,label
1,a
2,b
3,a
4,b
5,a
6,b
7,a
8,b
9,a
10,b"

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/train-test-split/?data=id%2Clabel%0A1%2Ca%0A2%2Cb%0A3%2Ca%0A4%2Cb%0A5%2Ca%0A6%2Cb%0A7%2Ca%0A8%2Cb%0A9%2Ca%0A10%2Cb&test_size=0.2&validation_size=0&stratify_column=label&stratify_bins=0&group_column=patient&shuffle=true&seed=42&header=true&delimiter=comma&output=sections

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.