Data Science Foundations · Intermediate

Time Series Lab

Keep chronology visible while trend, seasonality, lag relationships, smoothing, train/test cutoffs, and one-step forecasts change.

A deterministic synthetic time series exposes its generating components, trailing moving averages, lag relationships, chronological evaluation split, and a small lag-regression forecast. Playback keeps the learner oriented in time instead of treating ordered data like shuffled rows.

Step by step

  1. Generate an ordered signal with trend, seasonal structure, and noise.
  2. Reveal observations through time and overlay a trailing moving average.
  3. Inspect the known synthetic trend, seasonality, and noise components separately.
  4. Plot yₜ against yₜ₋lag and calculate training-period lag correlation.
  5. Create a chronological train/test cutoff without shuffling.
  6. Fit a lag regression before the cutoff and evaluate MAE/RMSE only on later observations.

Core formulas

Moving average

MAₜ = (1/w) Σₖ₌₀^{w−1} yₜ₋ₖ

A trailing window smooths recent observations without using future values.

Lag relation

(yₜ₋ₖ, yₜ)

Lag plots reveal whether past values have a useful relationship with current values.

Lag regression

ŷₜ = a + b·yₜ₋ₖ

The educational forecast learns a linear relationship using only pre-cutoff lag pairs.

When to use Time Series Lab

  • Understanding why chronological data cannot usually be randomly shuffled for evaluation.
  • Learning trend, seasonality, smoothing, and autocorrelation intuition.
  • Connecting lagged features to simple forecasting.

Primary references

scikit-learn — Lagged features for time series forecasting

scikit-learn — Time-related feature engineering