Lesson 2 of 4 Bias and Class Imbalance

Splitting, Shuffling and Augmenting Data to Reduce Bias

This lesson explains how splitting data into training, validation and test sets affects bias and evaluation reliability, and how shuffling, stratification and augmentation mitigate bias.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain the roles of training, validation and test sets.
  • Apply shuffling, stratification and group-aware splits.
  • Use augmentation and reweighting for under-represented groups.

Training, validation and test splits

Data is split into three sets with distinct roles. The training set is used to fit the model. The validation set is used to tune hyperparameters and decide when to stop training. The test set is used once, at the end, to estimate real-world performance; using it repeatedly for decisions makes its estimate optimistic. Common ratios are 70/15/15 or 80/10/10.

Data is usually shuffled before splitting so each set is representative, except for time series, which are split by time so the model is tested on later data than it was trained on. For small datasets, k-fold cross-validation trains k models, each validated on a different fold of the data, and averages the scores, which uses all the data for both training and validation.

Match the pairs

What each split is for

Exam skills 1.3.3

Match each data split with its job.

Log in to try this activity Interactive activities are free with an account.

Shuffling and stratification

Data is often stored in an order, such as by date, region or class. Splitting without shuffling can put all of one region or class in the test set. Shuffle before a random split, and use a stratified split to keep the same proportions of each class (and, if needed, each facet group) in every split. The exception is time series: split by time, training on the past and testing on the future, and never shuffle across time, or future information leaks into training. Groups of related records, such as several records from one patient, should be kept in one split.

The following diagram shows the grouped, stratified split.

Splitting the dermatology images. All images of one patient go to the same split, so the model is never tested on a patient it has seen. The split is stratified by skin-tone group, so the test set has enough darker-skin images to measure recall reliably, and augmentation is applied to darker-skin training images only.
Patient labels and the split sizes are illustrative.
Scenario questions

Split it fairly

Exam skills 1.3.3

Choose the split that gives a fair estimate of performance.

Log in to try this activity Interactive activities are free with an account.

Augmentation and reweighting

Augmentation creates additional training examples for under-represented groups: image transformations, text paraphrases, synthetic records. Resampling over-samples small groups or under-samples large ones, and reweighting gives examples from small groups more weight in the loss function. These are applied to the training set only; validation and test sets must keep the real distribution. The following table summarises the techniques.

TechniquePurposeCaution
Shuffle then splitAvoid ordered splitsNot for time series
Stratified splitSame class or group mix in each splitChoose the stratification column carefully
Time-based splitRealistic evaluation for temporal dataNo shuffling across time
Group splitKeep related records togetherNeeds a group ID
Augmentation, resampling, reweightingRepresent small groups betterTraining set only
True or false

Augmenting fairly

Exam skills 1.3.3 · 1.3.5

Check when augmentation and reweighting reduce bias.

Log in to try this activity Interactive activities are free with an account.
Worked example

A skin-condition classifier

A dermatology image dataset has 20,000 images, of which only 6% show darker skin tones, and some patients have up to 30 images each. The first model performs much worse on darker skin.

  • Split by patient ID so the same patient never appears in training and test sets.
  • Stratify by skin-tone group so the test set contains enough darker-skin images to measure performance reliably.
  • Augment darker-skin training images with rotations, crops and lighting changes, and collect more real images.
  • Report recall separately for each skin-tone group.

Augmentation alone cannot replace real data diversity, so collection is part of the fix, but stratified evaluation is what reveals whether the gap has closed.

Check yourself

Why should time series not be shuffled across time before splitting?

Show answer

The model would train on future data and look better than it will in production.

Exam Tips

Remember for the exam

  • Shuffle before random splits; never shuffle time series across time.
  • Stratified splits keep class and group proportions.
  • Keep all records of one entity in the same split.
  • Augment, resample and reweight the training set only.
  • Evaluate performance per group to detect bias.