Did the model succeed, or did the test leak the answers?
Choose the split unit by what will be new in real use
Shuffling frames into train and test looks tidy and still leaks. The split boundary should match what is new at use time.
Say you build a classifier that decides whether a video frame contains a car. You have 30 videos of 1,000 frames each. You shuffle all 30,000 frames and split 80/20. No file is in both sets, so it looks fine.
It is not. Frame 200 and frame 201 are nearly the same picture. The model is tested on scenes it has already seen, and can lean on background, lighting and camera angle instead of learning the distinction.
Leakage
Leakage is when building the model uses information that will not exist in the situation you are testing. The result is an optimistic score. You do not need a column called correct_answer; data preparation can leak too.
Split by the thing that must be new
To generalise to new videos, the unit of the split is the video, not the frame. All frames of a video stay together. If two videos are cuts of the same recording, use the recording id. If you need to work on new cameras, split by camera or site.
In scikit-learn, store a groupid per sample and use GroupShuffleSplit. One catch: testsize=0.2 means 20% of the groups, not 20% of the samples. A one-hour video and a one-minute video each count as one group, so check the resulting sample and class counts on each side.
The trade-off is real. Group splits can leave very few independent sources in the test set. Three videos of 1,000 frames each are not 3,000 independent scenes. Report that limit instead of printing an accuracy with three decimals.
Leakage with no videos at all
Normalising with the mean and standard deviation of the whole dataset, then splitting, lets test data influence preparation. The order is:
1. Split by the evaluation boundary. 2. fit the scaler on train only. 3. transform validation and test with those learned values.
A pipeline helps keep this honest. It will not fix a wrong choice of groups.
When the new thing is the future
Predicting tomorrow's load with a random split lets you train on the future and test on the past. Split by time: early for training, later for testing. TimeSeriesSplit does this, and its gap leaves room between the two. It does not fix a feature that already contains future information.
Two common mistakes
A habit worth keeping
Keep a manifest next to the data: sample id, source id, capture time, assigned split. Then you can reproduce what was tested and add a check that no group id appears in two splits. That check costs nothing compared with wasted GPU time.
Exercise
Finish this sentence for a dataset you know: "In real use, the new thing will be ___." Whatever fills the blank (row, user, recording, site, time period) is what must stay out of training.