Demand forecasting predicts how much of a product or service will be needed in the future. It drives inventory planning, staffing, pricing, and supply chain decisions. Getting it wrong means either stockouts (lost sales) or overstock (wasted capital).
Where It Is Used
Demand forecasting is critical across industries:
- Retail: SKU-level forecasting for inventory optimization
- E-commerce: Warehouse stocking, delivery capacity planning
- Manufacturing: Production scheduling, raw material ordering
- Energy: Load forecasting for grid management
- Transportation: Ride demand, flight booking predictions
- Hospitality: Hotel occupancy, restaurant reservations
Products: Amazon fulfillment, Uber surge pricing, Walmart inventory, Starbucks staffing.
Typical Data You Will See
| Aspect | Typical Values |
|---|---|
| Granularity | Hourly, daily, weekly |
| History length | 2-5 years |
| Entities | 1K to 1M SKUs/locations |
| Exogenous features | 10-50 variables |
| Forecast horizon | 1 day to 52 weeks |
Common table structure:
date | sku_id | location_id | sales_qty | price | promo_flag | stock_level
External data sources: - Calendar features: holidays, events, weekdays - Weather data: temperature, precipitation - Marketing: promotions, campaigns, ad spend - Economic indicators: GDP, consumer confidence - Competitor actions: pricing, launches
What You Do in Practice
- Define forecast scope - What entities, what horizon, what frequency?
- Gather historical data - Sales, inventory, stockouts, external factors
- Handle data issues - Missing days, zeros vs stockouts, outliers
- Identify patterns - Trend, seasonality, holiday effects, promotions
- Build hierarchy - Product categories, regions, aggregation levels
- Train baseline model - Simple exponential smoothing or seasonal naive
- Add ML models - Gradient boosting with lag features, or deep learning
- Reconcile forecasts - Ensure hierarchy consistency (store forecasts sum to region)
- Evaluate properly - Time-based splits, multiple horizons, business metrics
- Deploy and monitor - Track accuracy by segment, retrain on schedule
Baseline First
Two baselines every forecasting project needs:
- Seasonal naive: Predict same value as same period last year
- Captures yearly seasonality
- No tuning required
-
Often surprisingly competitive
-
Simple exponential smoothing: Weighted average of recent observations
- Captures level and trend
- Three parameters to tune
- Fast to compute
If your ML model cannot beat seasonal naive by 10%+, investigate data quality before adding complexity.
Common Models and When to Choose
| Model | Best For | Limitations |
|---|---|---|
| Exponential Smoothing (ETS) | Single series, clear patterns | No external features |
| ARIMA/SARIMA | Statistical analysis, confidence intervals | Complex tuning, slow |
| Prophet | Business data with holidays, multiple seasonalities | Can overfit, slow at scale |
| XGBoost with lag features | Many features, complex interactions | Requires careful feature engineering |
| LightGBM | Large scale, fast training | Same as XGBoost |
| DeepAR | Many related series, learned patterns | Requires significant data |
| Temporal Fusion Transformer | Complex multi-horizon, interpretability | Computationally expensive |
| N-BEATS | Strong benchmark, no feature engineering | Black box |
Industry default: Start with ETS or Prophet for baselines, move to gradient boosting or deep learning for production.
Feature Engineering Patterns
Lag features: - Sales 1, 7, 14, 28, 364 days ago - Rolling mean/std over 7, 28, 90 days - Difference from same period last year
Calendar features: - Day of week, month, quarter (cyclical encoding) - Holiday indicators (with lead/lag effects) - Payday indicators, school holidays
Promotional features: - Promo active flag - Discount depth - Days since/until promotion - Promo type encoding
External features: - Weather (temperature, rain probability) - Events (sports, concerts, local events) - Economic indicators
Hierarchical features: - Category-level trends - Store-level seasonality - Cross-series patterns
Evaluation and Metrics
Primary metrics:
| Metric | Formula | Use Case |
|---|---|---|
| MAPE | Mean Absolute Percentage Error | Easy to interpret, but fails on zeros |
| WMAPE | Weighted MAPE | Handles volume differences |
| RMSE | Root Mean Squared Error | Penalizes large errors |
| MAE | Mean Absolute Error | Robust to outliers |
| Bias | Mean Error (signed) | Detect systematic over/under forecasting |
Business metrics: - Service level: % of demand fulfilled - Inventory turns: How fast stock rotates - Stockout rate: % of time out of stock - Overstock cost: Capital tied in excess inventory
Pitfalls: - Evaluating only on aggregate (hides poor SKU-level performance) - Using MAPE when zeros are common - Not evaluating at the horizon that matters for decisions - Ignoring bias (systematic over or under forecasting)
Failure Modes and Debugging Checklist
- [ ] Data leakage: Using future information (e.g., actual promo results)
- [ ] Stockout confusion: Zeros are stockouts, not low demand
- [ ] Outlier distortion: Black Friday, COVID effects dominate model
- [ ] Seasonality mismatch: Model trained on wrong seasonal period
- [ ] Promotion blindness: Model does not capture promo effects
- [ ] New product cold start: No history for new SKUs
- [ ] Hierarchy inconsistency: Store forecasts do not sum to total
- [ ] Regime change: Fundamental demand shift not captured
Production Checklist
Before deployment: - [ ] Backtesting across multiple time periods - [ ] Performance acceptable across all hierarchy levels - [ ] Cold start strategy for new products - [ ] Outlier handling defined - [ ] Forecast intervals generated (not just point forecasts)
After deployment: - [ ] Daily accuracy monitoring by segment - [ ] Bias tracking (directional errors) - [ ] Automatic alert on accuracy degradation - [ ] Weekly/monthly retraining schedule - [ ] Feedback loop with actual sales data - [ ] Human override capability for special events
Tools and Stack
| Category | Tools |
|---|---|
| Statistical models | statsmodels, Prophet, statsforecast |
| ML models | XGBoost, LightGBM, scikit-learn |
| Deep learning | PyTorch, GluonTS, Darts, NeuralForecast |
| Scalable forecasting | Spark, Ray, Dask |
| Visualization | Plotly, matplotlib |
| Production | Airflow, MLflow, cloud ML platforms |
Example Mini-Case
Scenario: Grocery retailer needs daily SKU-level forecasts for 10K products across 200 stores.
Data: 3 years daily sales, promotions, holidays, weather.
Approach: 1. Baseline: Seasonal naive (same day last year) - WMAPE 35% 2. Feature engineering: Lag features, promo indicators, holiday effects 3. Model: LightGBM with 28-day forecast horizon 4. Hierarchy: Trained at SKU-store level, reconciled to category and store totals 5. Result: WMAPE 22%, 37% improvement
Production setup: - Nightly batch job computing next 28 days - Weekly model refresh - Daily accuracy dashboard - Alerts on WMAPE > 30% for any category
Business impact: 15% reduction in stockouts, 8% reduction in overstock.
Related Pages
- Index: ML Field Guide
- Time Series Anomaly Detection
- Financial Time Series
- Feature Engineering Fundamentals
Further Reading
- Forecasting: Principles and Practice (Hyndman)
- Prophet Documentation
- GluonTS Documentation
- Nixtla statsforecast
Try it live
Everything above runs in your browser — open Demand Forecasting Simulator and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Demand Forecasting Simulator simulation