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
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:- Trend: Long-term increase or decrease
- Seasonality: Regular patterns that repeat (daily, weekly, yearly)
- Cyclical: Irregular fluctuations (business cycles)
- 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.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
Seasonal Decomposition
Time Series Cross-Validation
Regular cross-validation doesn’t work for time series (can’t use future data to predict past).Practice Exercises
Exercise 1: Real Stock Data
Exercise 1: Real Stock Data
Problem: Download real stock data (e.g., using
yfinance) and:- Check for stationarity
- Transform to stationary (log returns)
- Fit ARIMA model
- Forecast next 5 days
Exercise 2: Seasonal Model
Exercise 2: Seasonal Model
Problem: Given monthly airline passenger data:
- Decompose into trend, seasonality, residual
- Fit SARIMA (Seasonal ARIMA)
- Forecast next 12 months
Exercise 3: Multi-Step Forecast
Exercise 3: Multi-Step Forecast
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.