Skip to content
AI360XpertBeta
Playgrounds

Foundations

Train/Test Split & CV

A held-out score is only as honest as the split and fitting procedure behind it.

Data seed 1

Guided steps 1 / 4

Stage 1 of 4: Dataset

Synthetic samples. Circle = A; square = B. Change Dataset size to add observations.

40 synthetic observations: 30 A and 10 B. Data seed 1, ordering seed 1.

  • Class A sample
  • Class B sample
Adjust parameters

Synthetic observations, with a three-to-one class mix.

Samples40Samples: 40
Class A30Class A: 30
Class B10Class B: 10

What can a model learn from these observations?

Each synthetic observation has a feature x and a class. There are three A observations for each B; the initial order groups A before B.

Observation

One row: a measured feature and the class the model is asked to predict.

Check this stage

Check your understanding

A held-out score is only as honest as the split and fitting procedure behind it. Move samples, inspect class coverage and compare a clean fit with deliberate leakage.

What does the split change?

The training set supplies examples for fitting a model. The held-out set supplies examples for assessing predictions after fitting. Here every synthetic observation has one feature, x, and a class, A or B. A threshold classifier chooses a cut in x and predicts a class on either side. It is fitted from the current training rows, not assigned a score from their proportions.

Start with One split. At the initial 40 observations and train share 0.75, the first 30 rows are all A and the last 10 are all B. Training never supplies a B example. This one-class fit predicts A everywhere, so it gets 0 of the 10 held-out observations right. Move Train share, or drag the neutral diamond, and inspect what changes on both sides.

The tiles show membership, not feature position: a circle is A, a square is B. Open Under the hood to see x, the fitted rule and each prediction. Change Dataset size to keep experimenting; New data changes feature values through the displayed data seed. The same settings and seeds reproduce the same experiment.

What does accuracy count?

For held-out observations, accuracy is the number correctly classified divided by the total scored. Suppose a fit uses (0.1, A), (0.2, A), (0.8, B) and (0.9, B). A threshold at 0.5 separates those training examples. On held-out (0.3, A) and (0.7, A), the model predicts A then B: one correct prediction out of two, or 0.5 accuracy.

The drawer shows the actual correct count, denominator and training accuracy for your current experiment. It also shows a training-majority baseline: always predict whichever class was most common in training. With imbalanced classes, compare that baseline and class coverage before treating accuracy as useful evidence.

Shuffle, stratify, then inspect

In Shuffle and stratify, Shuffle draws membership using the ordering seed. Reshuffle changes that seed while keeping the feature values fixed. The five-seed comparison uses the same observations with five reproducible random orders. These scores reveal sensitivity to membership; choosing the best seed would turn evaluation into model selection.

Stratify interleaves the classes to approximately preserve their proportions in each partition. It does not guarantee identical ratios, higher accuracy or independence. Ten rows cannot contain exactly 7.5 A and 2.5 B. If there are three B observations and ten folds, at least seven held-out folds must lack B.

Shuffling suits this synthetic example of independent observations. It is not a universal repair: related scans from one patient belong together when assessing new patients. For forecasting, train on the past and assess later observations using only features available at prediction time. A random row split can violate those tasks.

Let the held-out labels leak

Make a prediction before pressing Reveal the result. The card compares two real fits on the same membership: one uses training labels alone; the other includes held-out labels. Here the second fit searches the same complete family of threshold rules. The clean fit already gets as many training rows right as possible, so improving the combined count cannot sacrifice held-out correctness. Its held-out accuracy can rise or stay equal. That property is specific to this experiment; an unchanged score still does not make leakage acceptable.

Press Let held-out labels into fitting, or use the matching checkbox. The pipeline highlights the leaking fit step, and the current score is labelled contaminated. Back to working restores the complete previous experiment, including its seeds and ordering. Repair the challenge by excluding held-out labels and giving both classes to both sides; it does not ask you to hunt for a high score.

Learned preprocessing, including imputation, scaling and feature selection, must also be fitted within training partitions and applied to held-out rows using those fitted transformations. That is a leakage risk, but it is not the numerical experiment simulated here: positive affine scaling would preserve the ordering used by this one-feature threshold model. Duplicate or related records across partitions are another leakage risk. Stratifying labels does not resolve either problem. scikit-learn's leakage examples show preprocessing pipelines that enforce the boundary.

Rotate folds without hiding a failure

In Cross-validation, each held-out fold gets a fresh model fitted on all other folds. Step advances one fold; the selector and diamond let you inspect a particular fold directly. Changing the train-share slider is unnecessary here: ordinary k-fold CV determines its own training fraction from k and the fold sizes.

Press Hold out every B. The last fold contains all ten B observations, leaving only A for its clean fit. Inspect that zero score alongside every other fold and the mean. Turn Stratify on and compare class counts as well as scores. Larger k leaves more observations for each fit, costs more fits, and reduces the number assessed in each held-out fold. It does not guarantee a better estimate.

The mean is the arithmetic average of the unrounded fold accuracies. The displayed standard deviation uses divisor k and describes their spread. Unequal folds contribute equal weight to this fold mean; it is not necessarily the pooled fraction correct across all rows. Folds share training observations, so their scores are dependent. A small spread is not a confidence interval and cannot certify generalisation; stratification itself can make scores look more alike. Set k to 1 to see the limit: no training data, no fitted model, no accuracy. Zero would wrongly imply a model made and missed predictions. These distinctions follow the cross-validation guide.

Keep model selection away from the final test

The interactive scores are experiments on a fixed classifier. In a modelling project, use validation data or CV to choose features, model settings and preprocessing. Then assess the chosen procedure on a separate final test that those choices have not used, or use an outer evaluation loop with nested CV. Three separately named sets are not required when validation is supplied by CV, and naming a set “test” does not protect it if you repeatedly use its score to choose settings.

A clean split estimates performance under the conditions represented by its held-out observations. New populations, changing conditions and unavailable features can still invalidate that extrapolation. The nested CV example explains how selection can make an evaluation optimistic.

Stage recap

  1. Dataset

    Each synthetic observation has a feature x and a class. There are three A observations for each B; the initial order groups A before B.

  2. One split

    Move the train share handle or slider. A threshold classifier fits only the training rows; its held-out accuracy counts correct predictions on the other rows.

  3. Shuffle and stratify

    Shuffle changes membership; Stratify approximately preserves class proportions. Try fitting on held-out labels: the score is contaminated even when its value stays the same.

  4. Cross-validation

    Each fold takes a turn being held out while a fresh classifier fits the others. Inspect every score and class count. The spread describes these dependent scores; it is not a confidence interval.

Reference

Accuracy
Correct predictions / held-out observations. Compare with a baseline and class coverage.
Decision stump
The classifier here chooses one feature threshold and which class to predict on either side. A one-class fit predicts that class everywhere.
Stratification
Approximately preserve class proportions; integer counts and scarce classes limit what is possible.
Fold mean and spread
Arithmetic mean and population standard deviation of the unrounded fold accuracies. These dependent scores do not form a confidence interval.
Validation and final test
Use validation or CV to choose settings. Keep a separate final test untouched by those choices, or assess selection with nested CV.

Break it on purpose

A class-sorted split can omit a class from training. Including held-out labels in fitting is a separate failure: that score no longer measures independent evaluation. Neither a high mean nor a small fold spread proves the split is sound.