Time Series Split

Time Series Cross-Validation is a specialized evaluation strategy for temporal data that respects chronological order — training only on past data and testing on future data in each fold, because standard K-Fold cross-validation shuffles data randomly and would use "future" information to predict "the past" (a devastating form of data leakage that produces impossibly optimistic performance estimates for stock prices, sales forecasts, weather predictions, and any time-dependent prediction task).

What Is Time Series Cross-Validation?

  • Definition: A cross-validation approach (also called "walk-forward validation" or "rolling origin") where each fold uses an expanding or sliding training window of past data and tests on the immediately following future period — never allowing future data to inform past predictions.
  • Why Standard K-Fold Fails: K-Fold randomly shuffles data into folds. For time series, this means 2025 data could be in training while 2024 data is in testing — the model literally uses the future to predict the past. This leakage produces accuracy estimates that are impossible to achieve in real deployment.
  • The Golden Rule: "You cannot use tomorrow's data to predict today."

Standard K-Fold vs Time Series Split

AspectStandard K-FoldTime Series Split
Data orderShuffled randomlyChronological order preserved
Future in training?Yes ⚠️ (data leakage)Never ✓
Training windowRandom subsetPast data only (expanding or sliding)
Test windowRandom subsetNext future period only

How Time Series Split Works (Expanding Window)

FoldTraining DataTest DataGap
1Jan - MarAprNone
2Jan - AprMayNone
3Jan - MayJunNone
4Jan - JunJulNone
5Jan - JulAugNone

Training window expands each fold. The model always predicts the next unseen period.

Sliding Window Variant

FoldTraining DataTest DataWindow Size
1Jan - MarApr3 months
2Feb - AprMay3 months
3Mar - MayJun3 months
4Apr - JunJul3 months

Fixed-size training window — older data drops off, simulating concept drift.

Python Implementation

from sklearn.model_selection import TimeSeriesSplit

tscv = TimeSeriesSplit(n_splits=5, gap=0)
for train_idx, test_idx in tscv.split(X):
    X_train, X_test = X[train_idx], X[test_idx]
    y_train, y_test = y[train_idx], y[test_idx]

# With gap (e.g., 7-day gap to prevent immediate correlation leakage)
tscv = TimeSeriesSplit(n_splits=5, gap=7)

The Gap Parameter

GapPurposeUse Case
gap=0Test immediately after training periodStandard forecasting
gap=77-day buffer between train and testAvoid autocorrelation from consecutive days
gap=3030-day bufferMonthly forecasting with weekly seasonality

Common Applications

DomainTime UnitTypical Setup
Stock PredictionDailyTrain on 2 years, test on next month
Sales ForecastingWeeklyTrain on 52 weeks, test on next 4 weeks
WeatherHourlyTrain on 6 months, test on next week
Demand PlanningDailyExpanding window, 1-week test horizon

Time Series Cross-Validation is the only correct evaluation strategy for temporal data — respecting the chronological ordering that standard K-Fold violates, preventing the future-to-past data leakage that produces unrealistically optimistic performance estimates, and simulating the real deployment scenario where models must always predict from historically available data.

Take time series split further

Ask the copilot about this term, or have our engineers assess it against your process.