Practice in Lab: Purge a gap before a temporal validation window →
Purge a gap before a temporal validation window
Future deployment requires validation in the future of the training data. Shuffling time series can teach a model from later observations and then evaluate it on earlier ones. A gap additionally separates training from the validation boundary when features or labels have a lookahead horizon.
This contract uses integer timestamps and an inclusive validation interval. Training observations must be strictly earlier than start minus gap. Choosing the gap requires knowledge of feature availability and label construction; an arbitrary gap is not proof that the pipeline is free of leakage.
times=[1,2,3,4,5,6]
start,gap=5,1
print([i for i,t in enumerate(times) if t<start-gap])Review the design
A temporal split must be combined with point-in-time feature joins and train-only preprocessing. Time order alone does not prevent using a feature published after the prediction timestamp.
Your task
Implement temporal_split(times,start,end,gap) returning (train_indices,validation_indices), preserving row order. Train if t<start-gap; validate if start<=t<=end. Require start<=end and gap>=0.
The explanation opens here once every check passes.