Machine Learning
Time Series
Forecasting
Time Series Analysis & Forecasting
Time series analysis focuses on data collected over time, capturing trend, seasonality and autocorrelation to make reliable forecasts.
Basic Components of a Time Series
- Trend: long‑term increase or decrease in the series.
- Seasonality: repeating patterns at fixed periods (daily, weekly, yearly).
- Cyclical: long‑term cycles not tied to a fixed calendar frequency.
- Noise: random variation that is not explained by the above components.
Stationarity & Differencing
Many classical models (like ARIMA) assume the series is stationary, meaning its statistical properties (mean, variance) don’t change over time.
- Use plots and tests (e.g. ADF test) to check stationarity.
- Apply differencing (subtract previous values) to remove trend.
- Seasonal differencing can remove repeating seasonal patterns.
ARIMA Model Overview
ARIMA stands for AutoRegressive Integrated Moving Average and is denoted as ARIMA(p, d, q):
- p: order of autoregression (lagged values of the series).
- d: degree of differencing.
- q: order of moving average (lagged forecast errors).
Seasonal ARIMA (SARIMA) extends this with seasonal components (P, D, Q, m).
Machine Learning Approaches
Instead of classical time series models, you can also frame forecasting as a supervised ML problem:
- Create lag features (e.g.
y_{t-1}, y_{t-2}, ...) and use tree‑based models or linear models. - Use sliding windows over the time series to predict the next value.
- For multivariate series, include additional explanatory variables (exogenous features).
Train/Test Splits for Time Series
Unlike i.i.d. data, you cannot randomly shuffle time series when splitting:
- Use the first part of the series for training and the later part for testing.
- Use time‑based cross‑validation (rolling or expanding windows) for robust evaluation.