How to Build a Demand Forecasting Model: Time Series, Features and Accuracy
Build a demand forecasting model in six steps: define the target, clean history, engineer time series features, fit Prophet or ARIMA, and backtest.
By Galactic News Editorial · Published 2026-11-28T07:41:12+00:00 · Updated 2026-11-28T07:41:12+00:00
To build a demand forecasting model, gather clean historical sales at the right granularity, engineer time-based and business features, fit a time series model such as Prophet or ARIMA, backtest it with rolling origins, and measure error with MAPE or WAPE. This guide walks through each step with working Python patterns.
Demand forecasting is a time series problem with business context. Sales follow weekly and yearly cycles, respond to price changes and promotions, and break around holidays. A model that ignores those drivers will miss the peaks that matter most. The steps below keep the model honest: every choice is tested against held-out history before it reaches production.
How to build a demand forecasting model: step 1, define the target
Start by naming the target, the granularity, and the horizon. The target is usually units sold, but it can be revenue or orders. Granularity is the level you forecast at: product-store-day is common in retail, while product-region-week suits slower-moving goods. The horizon is how far ahead you need: 28 days is a standard retail horizon, and it matches the M5 forecasting competition setup.
Write these three decisions down before touching data. A model built for daily forecasts cannot be reused for weekly planning without retraining. A model built at product level cannot answer store-level stock questions. Ambiguity here becomes rework later.
Step 2: gather and clean the data
Collect at least two full years of history if you can. Two years lets the model see each season twice. Less history works, but seasonal estimates get shaky.
Build one table with a date column and a demand column. Then add the drivers: price, promotion flags, holidays, and any known events. Missing days matter. A day with no sales because the store was closed is different from a day with zero demand. Prophet handles missing days gracefully, but it cannot know why a day is missing. Fill gaps deliberately and document the choice.
Check for outliers before modeling. A bulk order, a data glitch, or a one-day stockout can distort the trend. Decide whether to cap, remove, or flag each outlier. Never delete data silently.
Step 3: engineer time series features
Features turn calendar and business knowledge into numbers the model can use. The most useful ones are lags, calendar features, and external drivers.
Lags are past values of demand: sales 7 days ago, 14 days ago, and 28 days ago. Rolling means smooth noise: the 7-day and 28-day average of past sales. Calendar features include day of week, month, and holiday flags. Price and promotion enter as drivers, but only if their future values are known at forecast time. A promotion flag you cannot predict is useless for forecasting.
Prophet handles much of this automatically. It models trend, seasonality, and holidays as components of an additive model: y(t) = g(t) + s(t) + h(t) + error. Trend is piecewise linear by default, seasonality uses Fourier terms, and holidays are indicator regressors. You can add extra regressors, such as price, with the add_regressor method.
Step 4: choose and fit the model
Three model families cover most demand forecasting work.
Prophet is the fastest starting point. It takes a dataframe with two columns, ds for the date and y for the value. Fit with m = Prophet(), then predict with m.predict() on a future dataframe built by make_future_dataframe. It handles missing data, holidays, and strong seasonal patterns with minimal tuning. Its main weakness is that it does not use yesterday's sales directly. It fits a smooth trend and seasonal pattern, so it can lag on sharp level shifts.
ARIMA and seasonal ARIMA, available in statsmodels, give more statistical control. The statsmodels ARIMA class covers the full SARIMAX(p, d, q) x (P, D, Q, s) family, including exogenous regressors. ARIMA suits series where recent values strongly predict the next value. It needs stationary data, so differencing is often required, and order selection takes more expertise than Prophet.
Gradient boosting models, such as LightGBM or XGBoost, treat forecasting as tabular regression. Each row is a date, and the columns are lags, calendar features, and drivers. These models often win competitions, including the M5 competition, because they use many features well. They need careful feature engineering and more data than Prophet or ARIMA.
Start with Prophet. Add ARIMA or gradient boosting when the backtest shows Prophet missing something specific.
Step 5: backtest with rolling origins
Never judge a model on the data it was trained on. Backtesting trains on history up to a cutoff date, forecasts the next horizon, and compares against actuals. Then the cutoff moves forward and the process repeats. This rolling-origin approach shows how the model performs across different seasons and conditions.
Use at least three backtest windows. One window can flatter a model by accident. Three windows across different seasons give a fairer picture.
Measure error with metrics that suit the business. MAPE, mean absolute percentage error, is easy to explain but breaks when actual demand is zero. WAPE, weighted absolute percentage error, divides total absolute error by total actual demand, which handles zeros and weights high-volume items more. RMSE, root mean squared error, penalizes large misses heavily. Report at least two metrics, and always report them per product group, not just overall. A good overall score can hide terrible forecasts for slow movers.
Step 6: deploy and monitor
A forecast is a living artifact. Retrain on a schedule, weekly or monthly, and track error over time. Set an alert when error drifts above the backtest baseline. Drift usually means something changed: a new competitor, a price change, or a broken data feed.
Keep the pipeline simple. A script that reads the sales table, retrains the model, writes forecasts to a table, and logs error metrics is enough. Automate that before adding complexity. Version the model and the data snapshot with each run, so a bad forecast can be traced back to its inputs.
Common mistakes
- Forecasting at the wrong granularity. Daily forecasts for lumpy, slow-moving items are mostly noise. Aggregate to weekly.
- Leaking the future. A feature built from data that would not exist at forecast time inflates backtest scores and fails in production.
- Ignoring stockouts. Zero sales during a stockout is not zero demand. Treat censored demand explicitly or the model learns to under-forecast.
- One metric for everything. MAPE alone hides problems. Pair it with WAPE and a per-group breakdown.
- Skipping the backtest. A model that was never tested on held-out data is a guess with extra steps.
Bottom line
Build the model in this order: define target, granularity, and horizon; clean two years of history; engineer lags, calendar, and driver features; start with Prophet; backtest with rolling origins using MAPE and WAPE; then deploy with scheduled retraining and error monitoring. Most demand forecasting failures come from skipped steps, not from the wrong algorithm. A simple model tested properly beats a sophisticated model that was never backtested.