Skip to main content
Time Series Fundamentals

Time Series Fundamentals

What Makes Time Series Special?

In regular ML, data points are assumed to be independent. In time series, order matters and past values predict future values. Analogy: Regular ML is like looking at a bag of random photographs — each one is independent, and you can shuffle them freely. Time series is like watching a movie — each frame only makes sense in sequence, and what happened 5 seconds ago tells you a lot about what is happening now. Shuffling the frames destroys the information.
Estimated Time: 4-5 hours
Difficulty: Intermediate
Prerequisites: Descriptive Statistics, Probability, Regression
What You’ll Build: Stock price forecaster, seasonal decomposition tool

Time Series Components

Every time series can be decomposed into:
  1. Trend: Long-term increase or decrease
  2. Seasonality: Regular patterns that repeat (daily, weekly, yearly)
  3. Cyclical: Irregular fluctuations (business cycles)
  4. Residual: Random noise

Stationarity: The Key Assumption

Most time series methods assume stationarity - statistical properties don’t change over time. Analogy: Stationarity means the “rules of the game” stay constant. A stationary time series is like a casino where the odds never change — the house edge is always the same, no matter when you play. A non-stationary series is like a game where the rules keep shifting — the average changes, the volatility changes, and any strategy you learned yesterday might not work tomorrow. Most forecasting models need stationary data because they assume the patterns they learned in the past will continue into the future.
ML Application — Distribution Shift Detection: Stationarity is directly related to one of the biggest problems in production ML: distribution shift (also called dataset shift or concept drift). When the statistical properties of incoming data change over time, your model’s training assumptions break. Monitoring stationarity of input features using rolling statistics and the Augmented Dickey-Fuller test — the same tools from time series analysis — is one of the most effective ways to detect when your production model needs retraining. Companies like Netflix and Uber run these checks continuously on their feature pipelines.

What Stationarity Means

Making Series Stationary


Autocorrelation: Memory in Time Series

Autocorrelation measures how correlated a time series is with lagged versions of itself. Analogy: Autocorrelation measures “memory” in a time series. Think of it like asking: “If today was a hot day, how much does that tell me about tomorrow?” If there is high autocorrelation at lag 1, hot days tend to be followed by hot days (weather has memory). If autocorrelation is zero, each day is independent of the last (like coin flips). The ACF plot shows you exactly how many days of “memory” your data has — and that directly tells you how many past values to include as features in your forecasting model.

ACF vs PACF


Simple Forecasting Methods

Moving Average

Exponential Smoothing


ARIMA Models

ARIMA(p, d, q) combines:
  • AR(p): Autoregressive - regression on past values
  • I(d): Integrated - differencing for stationarity
  • MA(q): Moving Average - regression on past errors
yt=c+ϕ1yt1+...+ϕpytp+θ1ϵt1+...+θqϵtq+ϵty'_t = c + \phi_1 y'_{t-1} + ... + \phi_p y'_{t-p} + \theta_1 \epsilon_{t-1} + ... + \theta_q \epsilon_{t-q} + \epsilon_t Where yty'_t is the differenced series.

Seasonal Decomposition


Time Series Cross-Validation

Regular cross-validation doesn’t work for time series (can’t use future data to predict past).
Statistical Mistake in ML — Random Splitting Time Series Data: One of the most common and damaging mistakes in applied ML is using random train/test splits on time series data. If your training set includes data from March and your test set includes data from February, you are literally training on the future to predict the past. This creates a subtle but severe data leakage that inflates your metrics. Your model appears to perform brilliantly in evaluation but fails catastrophically in production. Always use time-based splits: train on the past, test on the future. This applies not just to pure time series forecasting but to any problem where data has a temporal ordering — user behavior, financial transactions, sensor readings, and more.

Practice Exercises

Problem: Download real stock data (e.g., using yfinance) and:
  1. Check for stationarity
  2. Transform to stationary (log returns)
  3. Fit ARIMA model
  4. Forecast next 5 days
Problem: Given monthly airline passenger data:
  1. Decompose into trend, seasonality, residual
  2. Fit SARIMA (Seasonal ARIMA)
  3. Forecast next 12 months
Problem: Compare different forecasting methods (MA, ES, ARIMA) using rolling window validation. Which performs best at different forecast horizons (1-day, 7-day, 30-day)?

Summary

Key Takeaway: Time series analysis is about understanding temporal dependencies. Before applying any model, always check for stationarity and understand the autocorrelation structure. The goal is to capture the patterns (trend, seasonality) while forecasting with quantified uncertainty.