Chronological and gap splits
Quick answer
Chronological splitting evaluates predictions on later observations using only earlier information. A gap removes rows near the train-validation boundary when labels or features overlap across time. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Inspect expanding windows
from sklearn.model_selection import TimeSeriesSplitfor tr,va in TimeSeriesSplit(n_splits=3,test_size=2,gap=1).split(range(10)): print(tr.tolist(),va.tolist())Observed local output:
[0, 1, 2] [4, 5][0, 1, 2, 3, 4] [6, 7][0, 1, 2, 3, 4, 5, 6] [8, 9]A one-row gap separates each train end and validation start.
How it works
TimeSeriesSplit expects rows in chronological order; it returns expanding training prefixes by default and later validation blocks. Its gap parameter counts excluded samples, not clock time. max_train_size optionally bounds the training window; test_size controls validation row count. Equally spaced observations make equal-size validation blocks cover equal durations; irregular timestamps may require custom calendar splits. Example: with hourly observations and a target defined by the next 24 hours, ensure every training target has become observable before the validation prediction timestamp. A gap of 24 rows may work for hourly data but is not a universal rule: delayed labels, rolling feature windows, duplicated entities and irregular times may require a timestamp-aware embargo or combined group-time split. Fit preprocessing on the training prefix and construct lagged features using only information available at prediction time. Define whether future predictions are rolling one-step or fixed-horizon; that changes what feedback is allowed. Report train end, validation start and end, label availability and gap. Keep the latest final horizon separate.
Filter labels by availability
rows=[(0,3),(1,4),(2,5),(3,6),(4,7)]start=5print([t for t,available in rows if t<start and available<=start])Observed local output:
[0, 1, 2]This policy permits labels available exactly at the prediction cutoff; a strict-before policy would exclude equality.
Common mistakes
Do not shuffle before forecasting CV, interpret gap as elapsed time, or assume a gap alone fixes features computed with future information. Sort timestamps and handle equal-time records as a unit when necessary.
Practice and next steps
For a label available three hours after the feature timestamp, decide which training labels can be used at a 12:00 validation start. Explain how missing hours change a row-count gap. Complete the knowledge check and staged exercise. Next: Nested CV.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Chronological and gap splits — knowledge check
Apply chronological and gap splits to new scenarios.
What does TimeSeriesSplit gap count?
Which label may enter training?
What does an expanding window do?
What about irregular observations?
Why use point-in-time features?