1 · What makes time series special
A time axis breaks the one assumption every other ML track relies on — that rows are independent and shuffle-able. Order is information, and you must never shuffle.
A time series is data indexed by time, where each point is correlated with its recent past (autocorrelation). That breaks the i.i.d. assumption: you cannot shuffle rows, and you must split train/test by time — the future must never leak into the past.
Without this:
Treat a time series like ordinary tabular data and you'll shuffle away the signal, leak the future into training, and report fantasy accuracy that collapses in production.
Every ML track you've done so far assumed your rows are i.i.d. — independent and identically distributed. That assumption justifies shuffling, random train/test splits, and k-fold cross-validation. Time series data breaks it.
A time series is a sequence of observations indexed by time: daily sales, hourly temperature, a stock's price per minute. Two things make it special:
-
Order is information. The value today is correlated with yesterday's (and last week's, and last year's). This dependence on the past is called autocorrelation, and it's the entire signal we exploit to forecast. Shuffle the rows and you destroy it.
-
The future must never leak into the past. You can only train on data that came before what you're predicting. That kills random splits and standard k-fold CV — you must split by time (train on the past, test on the future) and validate with walk-forward schemes (Chapter 5).
The goal is forecasting: given the history up to time t, predict t+1, t+2, …. Below we build a synthetic series with the three ingredients every real series has — trend, seasonality, and noise — and then show concretely why shuffling is catastrophic: it leaves the mean and variance untouched but annihilates the autocorrelation that makes forecasting possible.
Python (in browser)
A time series is a pandas Series on a DatetimeIndex. Shuffling preserves mean/std but annihilates the autocorrelation — proof that order is the signal.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Why can't you use a normal random train/test split (or k-fold CV) on a time series?
- A time series is data indexed by time; consecutive points are autocorrelated, breaking the i.i.d. assumption.
- Never shuffle: order is the signal. Shuffling preserves mean/std but destroys the autocorrelation you forecast from.
- Split train/test by time (past → future) and validate walk-forward; the future must never leak into the past.
Demand forecasting, anomaly detection on metrics, finance, weather, and capacity planning — anywhere the data has a clock.
If you remove it: Without respecting time order you leak the future into training and ship models that look great offline and fail live.