Hi,πŸ‘‹ we have updated the app and fixed multiple bugs. We are lacking funds, request to free user not to use Adblock. Ads are non intrusive. 😊

@_avichawla: Andrew Ng's team once made a b...

@_avichawla
7 views Jul 19, 2025
1
Andrew Ng's team once made a big mistake in a research paper.

And it happened due to randomly splitting the data.

Here's what happened:
2
It is common to generate train and validation sets using random splitting.

However, in many situations, it can be fatal for model building.

Let's learn below!
Media image
3
Consider building a model that generates captions for images.

Due to the inherent nature of language, every image can have many different captions.

- Image-1 β†’ Caption-1, Caption-2, Caption-3, etc.
- Image-2 β†’ Caption-1, Caption-2, Caption-3, etc.

Check this πŸ‘‡
Media image
4
If we use random splitting, the same data point (image) will be available in the train and validation sets.

As a result, we end up evaluating the model on the instances it was trained on.

This is an example of data leakage (also called group leakage), resulting in overfitting!
Media image
5
Group shuffle split solves this.

There are two steps:
1) Group all training instances corresponding to one image.
2) After grouping, the ENTIRE GROUP (all examples of one image) must be randomly assigned to the train or validation set.

This will prevent the group leakage.
Media image
6
If you use Sklearn, the GroupShuffleSplit implements this idea.

Here's the module that implements this πŸ‘‡
Media image
7
As an example, consider we have the following dataset:

- x1 and x2 are the features.
- y is the target variable.
- group denotes the grouping criteria.

Check this πŸ‘‡
Media image
8
First, we import the GroupShuffleSplit from sklearn and instantiate the object.

Check this πŸ‘‡
Media image
9
The split() method of this object lets us perform group splitting:

This is how to invoke itπŸ‘‡
Media image
10
The above method returns a generator, and we can unpack it to get the following output:

- The data points in groups β€œA” and β€œC” are together in the training set.
- The data points in group β€œB” are together in the validation/test set.

Check this πŸ‘‡
Media image
11
The same thing happened in Andrew Ng's paper, where they prepared a medical dataset to detect pneumonia.

- Total images = 112k
- Total patients = 30k

Due to random splitting, the same patient's images were available both in the training and validation sets.

Check this πŸ‘‡
Media image
12
This led to data leakage, and validation scores looked much better than they should have.

A few days later, the team updated the paper after using the group shuffle split strategy to ensure the same patients did not end up in both the training and validation sets.

Check this πŸ‘‡
Media image
13
That's a wrap!

If you found it insightful, reshare it with your network.

Find me β†’ @_avichawla
Every day, I share tutorials and insights on DS, ML, LLMs, and RAGs.
Actions
Visual Editor Carousel Maker NEW
Update Thread
What You Can Do
  • Download as PDF
  • Save to Notion
  • Export as Markdown
  • Visual Editor
  • LinkedIn & Instagram Carousel Maker
Create Free Account

Includes 7-day Premium trial