š Introduction
Time Series Forecasting is a machine learning and statistical technique used to predict future values based on historical observations recorded over time. Unlike traditional regression problems, time series data contains a temporal order, making trends, seasonality, and autocorrelation essential for accurate forecasting.
Four of the most widely used forecasting algorithms are ARIMA, SARIMA, Holt-Winters Exponential Smoothing, and Prophet. Each algorithm is designed to handle different types of time-dependent patterns.
Information
šÆ Learning Objectives
- Understand the fundamentals of time series forecasting.
- Learn trend, seasonality, and stationarity concepts.
- Understand ARIMA, SARIMA, Holt-Winters, and Prophet algorithms.
- Compare forecasting algorithms and their applications.
š What is Time Series Data?
A time series is a sequence of observations collected at regular time intervals. Unlike ordinary datasets, the order of observations carries important information because current values often depend on previous values.
| Characteristic | Time Series |
|---|---|
| Observation Order | Chronological |
| Prediction Target | Future Values |
| Learning Type | Statistical & Machine Learning |
| Main Objective | Forecast Future Observations |
š Components of a Time Series
| Component | Description |
|---|---|
| Trend | Long-term upward or downward movement. |
| Seasonality | Regular repeating patterns over fixed intervals. |
| Cyclic Pattern | Long-term fluctuations without a fixed period. |
| Noise | Random unexplained variation. |
š Stationarity
Many forecasting algorithms assume that the statistical properties of the time series remain constant over time. Such a series is called stationary.
| Property | Stationary Series |
|---|---|
| Mean | Constant |
| Variance | Constant |
| Autocorrelation | Stable over time |
Remember
š² ARIMA (AutoRegressive Integrated Moving Average)
ARIMA is one of the most popular statistical forecasting models for non-seasonal time series. It combines three components:
- AR (AutoRegressive) ā Uses previous observations.
- I (Integrated) ā Applies differencing to achieve stationarity.
- MA (Moving Average) ā Models previous prediction errors.
Model Notation
| Parameter | Description |
|---|---|
| p | Number of autoregressive terms. |
| d | Degree of differencing. |
| q | Number of moving average terms. |
AR Model
š³ SARIMA (Seasonal ARIMA)
SARIMA extends ARIMA by incorporating seasonal behavior. It models both short-term and seasonal dependencies in the data.
| Seasonal Parameter | Description |
|---|---|
| P | Seasonal autoregressive order. |
| D | Seasonal differencing. |
| Q | Seasonal moving average order. |
| m | Seasonal period (e.g., 12 for monthly yearly seasonality). |
Tip
š Holt-Winters Exponential Smoothing
Holt-Winters forecasting extends exponential smoothing by modeling three components simultaneously:
- Level
- Trend
- Seasonality
Level Update
Trend Update
Seasonal Update
Holt-Winters supports both Additive and Multiplicative seasonality depending on whether seasonal effects remain constant or change with the series level.
š¤ Prophet
Prophet, developed by Meta (Facebook), is a forecasting algorithm designed to handle business time series containing trend changes, multiple seasonalities, holidays, and missing observations with minimal manual tuning.
Prophet Model
Where:
- g(t) ā Trend.
- s(t) ā Seasonality.
- h(t) ā Holiday effects.
- ε(t) ā Random error.
Remember
āļø General Forecasting Workflow
Collect historical time series data.
Handle missing values and outliers.
Analyze trend, seasonality, and stationarity.
Select and train a forecasting model.
Generate future forecasts.
Evaluate forecasting accuracy.
š³ Forecasting Pipeline
š Algorithm Comparison
| Feature | ARIMA | SARIMA | Holt-Winters | Prophet |
|---|---|---|---|---|
| Trend | Yes | Yes | Yes | Yes |
| Seasonality | No | Yes | Yes | Yes |
| Holiday Effects | No | No | No | Yes |
| Handles Missing Data | Limited | Limited | Limited | Excellent |
| Ease of Use | Moderate | Moderate | Easy | Very Easy |
šļø Important Hyperparameters
| Algorithm | Important Hyperparameters |
|---|---|
| ARIMA | p, d, q |
| SARIMA | P, D, Q, m |
| Holt-Winters | trend, seasonal, seasonal_periods |
| Prophet | changepoint_prior_scale, seasonality_mode, holidays |
š Evaluation Metrics
- Mean Absolute Error (MAE)
- Mean Squared Error (MSE)
- Root Mean Squared Error (RMSE)
- Mean Absolute Percentage Error (MAPE)
- Symmetric Mean Absolute Percentage Error (sMAPE)
āļø Advantages and Limitations
- Captures temporal dependencies.
- Supports trend and seasonality modeling.
- Widely applicable across industries.
- Produces interpretable forecasts.
- Prophet requires minimal manual tuning.
- ARIMA assumes stationarity.
- Traditional statistical models may struggle with highly nonlinear patterns.
- Hyperparameter selection can be challenging.
- Forecast uncertainty generally increases over longer horizons.
- Structural changes can reduce forecast accuracy.
š Real-World Applications
| Application | Purpose |
|---|---|
| š° Financial Forecasting | Predict stock prices and market indicators. |
| š Sales Forecasting | Estimate future product demand. |
| ā” Energy Forecasting | Predict electricity consumption. |
| š¦ļø Weather Prediction | Forecast temperature and rainfall. |
| š„ Healthcare | Predict disease outbreaks and hospital admissions. |
| š Supply Chain | Optimize inventory and logistics planning. |
š» Practical Example
ARIMA Forecasting Using Statsmodels
import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
# Sample monthly sales data
sales = pd.Series([
120, 135, 128, 142, 150, 165,
172, 180, 178, 190, 205, 215
])
# Train ARIMA model
model = ARIMA(
sales,
order=(2,1,1)
)
model_fit = model.fit()
# Forecast next 3 periods
forecast = model_fit.forecast(steps=3)
print("Forecast:")
print(forecast)ā ļø Common Mistakes
- Ignoring stationarity before applying ARIMA.
- Confusing trend with seasonality.
- Using random train-test splits instead of chronological splits.
- Forecasting too far beyond the available historical data without accounting for increasing uncertainty.
- Failing to evaluate residuals after model training.