Dem& Forecasting Analytics

Chapter 7
Machine Learning and AI for Demand Forecasting

Post Graduate Program in Logistics
Dem& Forecasting Analytics   •   Post Graduate

Machine Learning and AI for Demand Forecasting

Introduction and Context

Demand forecasting estimates future customer demand for a product, service, location, or logistics activity. In logistics, forecasts support procurement, inventory positioning, warehouse capacity, transport planning, labour scheduling, replenishment, and customer-service commitments. Traditional forecasting methods remain important, but contemporary supply chains generate large volumes of transactional, operational, behavioural, and external data. Machine learning (ML) and artificial intelligence (AI) can exploit these data to model nonlinear relationships, interactions, intermittent demand, changing customer behaviour, and many related demand series.

ML should not be viewed as an automatic replacement for statistical forecasting or managerial judgement. It is a modelling approach whose value depends on data quality, validation design, operational integration, monitoring, and governance. A complex model can produce less useful forecasts than a simple seasonal benchmark if the data are sparse, the forecast horizon is long, or the model is allowed to learn information unavailable at the time of prediction.

Learning Objectives

By the end of this chapter, the reader should be able to:

  1. Construct forecasting features without temporal leakage.
  2. Explain regularization and its role in controlling overfitting.
  3. Compare tree-based ensembles, neural networks, probabilistic models, and statistical benchmarks.
  4. Design time-aware training, validation, and model-selection procedures.
  5. Interpret forecasts using explainability tools and uncertainty measures.
  6. Diagnose overfitting, concept drift, data drift, and forecast deterioration.
  7. Design human oversight and governance for AI-supported forecasting.

1. Forecasting as a Supervised Learning Problem

Let yt denote demand observed at time t. A supervised forecasting model estimates future demand from information available at the forecast origin:

ŷt+h = fh(Xt; θ)

Here, h is the forecast horizon, Xt is the feature vector available at time t, θ is the set of learned parameters, and ŷt+h is predicted demand. For multiple horizons, either a separate model can be trained for each h (direct forecasting), or one model can generate a sequence recursively (recursive forecasting). Direct models avoid the accumulation of recursive errors but require more models; recursive models are economical but may propagate early errors.

A forecasting dataset must reproduce the information state that existed when a decision would have been made. For example, a model predicting weekly demand on Monday must not use a promotion flag, inventory adjustment, or sales total that became known only on Friday. This is temporal leakage, and it can make offline accuracy appear excellent while producing poor operational forecasts.

Forecasting horizons and decision alignment

The horizon should match the decision lead time. A distribution centre may need a daily forecast for labour allocation, a weekly forecast for replenishment, and a monthly forecast for capacity planning. The target, feature availability, loss function, and evaluation horizon should therefore be designed jointly. Forecasting demand at a product-location level may also require reconciliation so that detailed forecasts are coherent with category, region, and network totals.

2. Feature Engineering for Demand

Feature engineering converts raw records into explanatory variables. It often determines performance more strongly than the choice between two sophisticated algorithms.

2.1 Time and calendar features

Useful variables include day of week, week of year, month, holiday proximity, financial period, school term, pay-cycle position, and days since a product launch. Cyclic variables can represent periodicity without treating December and January as distant. For period length P, the cyclic encoding is:

xt = sin(2πt/P), zt = cos(2πt/P)

The integer t identifies the calendar position and P is the cycle length, such as 7 for a weekly cycle or 12 for a monthly cycle. Both variables are required because sine alone cannot uniquely identify every position in a cycle.

2.2 Lag and rolling features

Lag features include previous demand values, such as yt-1, yt-7, and yt-28. Rolling features summarize recent history. A trailing mean over k observations is:

mt = (1/k) ∑i=1k yt-i

The index begins at t-1, not t, when the feature is used to predict yt. This prevents the target from entering its own predictor. Rolling standard deviation can represent recent volatility, while rolling minimum and maximum can help identify unusual demand regimes. For intermittent demand, the number of periods since the last nonzero sale and the recent demand occurrence rate are often informative.

2.3 Commercial and operational features

Potential predictors include price, discount depth, promotion type, display placement, stock availability, order backlog, lead time, competitor price, marketing exposure, weather, local events, and macroeconomic indicators. A critical distinction is between demand and observed sales. If an item stocked out, recorded sales may understate unconstrained demand. Stock availability should therefore be included as a feature, and censored observations should be flagged or modelled explicitly.

Features must be available at prediction time and have a plausible causal or predictive relationship. Future promotions may be legitimate predictors if they are scheduled and known in advance; future realized promotion compliance is not.

3. Statistical Foundations and Regularization

A useful baseline is linear regression with engineered features:

yt = β0 + β1x1,t + ⋯ + βpxp,t + εt

Here, β0 is the intercept, βj are coefficients, xj,t are predictors, and εt is an error term with conditional mean zero under the usual predictive interpretation. Linear models are interpretable and often effective when relationships are approximately additive. They may be fitted to transformed demand, for example log(1+yt), when demand is nonnegative and highly skewed. Any back-transformation must be handled carefully because, in general, E(exp(Z)) ≠ exp(E(Z)) when Z is random.

With many correlated lags and promotional variables, ordinary least squares may overfit. Ridge regression adds an L2 penalty:

min_β { ∑t=1n(yt - β0 - Xtβ)2 + λ∑j=1pβj2 }

Lasso regression uses an L1 penalty:

min_β { ∑t=1n(yt - β0 - Xtβ)2 + λ∑j=1p|βj| }

The observations are indexed by t, n is the training size, p is the number of predictors, β is the coefficient vector, and λ ≥ 0 controls penalty strength. The intercept is usually not penalized. Ridge shrinks correlated coefficients toward one another and generally retains all variables; lasso can set some coefficients exactly to zero. Elastic net combines both penalties:

λ[α∑j=1p|βj| + (1-α)∑j=1pβj2]

where 0 ≤ α ≤ 1. Regularization is selected using time-aware validation, not random shuffling. Predictors should generally be standardized when penalty magnitudes are compared across variables. Tree models are less sensitive to scaling.

4. Tree-Based Ensembles

Decision trees divide the feature space into regions and assign a prediction to each region. A single tree can represent nonlinearities and interactions, but deep trees have high variance. Ensembles improve stability by combining many trees.

Random forests

A random forest fits trees to bootstrap samples and considers a random subset of variables at each split. Averaging many trees reduces variance. It handles nonlinear effects, mixed feature scales, and interactions with limited preprocessing. However, it may extrapolate poorly beyond the range of training demand, and standard impurity-based importance can be misleading when predictors are correlated.

Gradient-boosted trees

Gradient boosting builds trees sequentially, with each new tree reducing the loss left by previous trees. A generic additive form is:

FM(x) = F0(x) + ∑m=1M η hm(x)

Here, hm(x) is the mth tree, M is the number of trees, η is the learning rate, and F0(x) is the initial prediction. Small learning rates and controlled tree depth can improve generalization, but usually require more trees. Early stopping uses a temporally later validation set to stop training when validation loss no longer improves.

Boosted trees are powerful for tabular demand data, especially when promotions, prices, calendar variables, and lags interact. They require careful treatment of missing values, categorical variables, extreme events, and extrapolation. Forecast intervals can be generated using quantile loss or ensembles, but an interval is useful only if its coverage is empirically checked.

5. Neural Networks for Demand Forecasting

Neural networks learn layered transformations. A basic hidden unit can be written as:

h = σ(Wx + b)

where x is the input vector, W is a weight matrix, b is a bias vector, and σ is an activation function. The network’s weights are learned by minimizing a loss function through gradient-based optimization.

Feed-forward networks use engineered lags and external variables. Recurrent neural networks, including long short-term memory (LSTM) and gated recurrent unit architectures, process sequences and can represent longer dependencies. Convolutional or temporal convolutional networks use filters over time. Attention-based architectures can assign different weights to historical positions and covariates, and are increasingly used for multi-horizon forecasting.

Neural networks are attractive when there are many related series, long histories, high-dimensional covariates, or hierarchical patterns. Global models train across products and locations, allowing information sharing. Static attributes such as product category, region, or channel can be represented using embeddings. Local models, by contrast, fit one model per series and may be preferable when products have strongly different dynamics or limited cross-series similarity.

Their disadvantages include sensitivity to scaling, missing data, hyperparameter choices, computational cost, and limited transparency. More layers do not guarantee better forecasts. Dropout, weight decay, early stopping, data augmentation where appropriate, and careful validation can reduce overfitting.

6. Probabilistic AI and Forecast Uncertainty

A point forecast alone does not reveal operational risk. A probabilistic forecast estimates a distribution or selected quantiles of future demand. Let Ft+h(y) denote the predictive cumulative distribution for demand at horizon h. A central prediction interval from lower quantile qL to upper quantile qU is:

[QqL(Ft+h), QqU(Ft+h)]

where Qq is the q quantile. A nominal 90% interval should contain the realized value about 90% of the time over a suitably representative evaluation sample; this property is called calibration. Calibration does not imply that the interval is narrow or operationally useful.

Quantile regression minimizes the pinball loss. For error e = y - ŷq and quantile q ∈ (0,1), one common form is:

Lq(e) = q·max(e,0) + (1-q)·max(-e,0)

Under suitable conditions, minimizing expected pinball loss produces the conditional q quantile. Distributional neural networks may predict parameters of a count, Poisson, negative binomial, or other distribution. Count distributions are suitable only when their assumptions fit the data; overdispersion, excess zeros, and stockout censoring may require alternatives or hierarchical models.

Probabilistic forecasts support safety-stock decisions, capacity buffers, and scenario planning. However, forecast uncertainty is not the same as all supply-chain uncertainty. Lead-time variability, supplier failure, transportation disruption, and capacity constraints should be modelled or added to decision simulations where relevant.

7. Comparing ML with Statistical Models

Statistical models such as exponential smoothing, ARIMA, Croston-type methods, and dynamic regression offer strong baselines and interpretable assumptions. They are particularly competitive for stable, seasonal, or short data series. ML models often outperform when there are many exogenous predictors, nonlinear interactions, and cross-sectional series that can share information.

CriterionStatistical modelsML and AI models
Data requirementOften effective with short historiesUsually benefit from larger, richer datasets
NonlinearityLimited or explicitly specifiedStrong, especially trees and neural networks
InterpretabilityOften highVaries; requires explanation tools
Exogenous variablesSupported, with careful specificationNaturally handles many covariates
ExtrapolationDepends on model structureOften weak outside learned ranges
UncertaintyEstablished methods for many modelsMust be designed and calibrated
MaintenanceOften simplerRequires monitoring, retraining, and governance

The correct comparison is empirical and decision-oriented. A naïve seasonal forecast, where demand is predicted using the corresponding prior seasonal period, should be included. For a weekly seasonal series, a possible benchmark is ŷt = yt-7. The benchmark’s lag must match the data frequency and seasonality.

8. Evaluation, Overfitting, and Temporal Validation

Random train-test splits are generally inappropriate for time series because they allow future patterns to influence training. A rolling-origin design trains on an earlier interval and evaluates on the next interval, then moves the origin forward. Validation must preserve the operational information set and forecast horizon.

Common point metrics include mean absolute error:

MAE = (1/n)∑i=1n|yi-ŷi|

and root mean squared error:

RMSE = √[(1/n)∑i=1n(yi-ŷi)2]

n is the number of evaluated forecasts, yi is actual demand, and ŷi is predicted demand. MAE is in the units of demand and weights errors linearly; RMSE is also in demand units but penalizes large errors more heavily. Percentage metrics can be unstable when demand is zero or near zero. Weighted absolute percentage error can be written as:

WAPE = ∑|yi-ŷi| / ∑|yi|

provided the denominator is nonzero. No single metric captures all business priorities. Service-level, stockout, waste, expedite, and working-capital costs should be evaluated alongside statistical accuracy.

Overfitting occurs when a model captures noise or historical peculiarities that do not persist. Warning signs include a large train-validation gap, strong performance deterioration at longer horizons, unstable feature importance, and sensitivity to small data changes. Controls include simpler architectures, regularization, feature reduction, early stopping, rolling validation, and post-deployment monitoring.

9. Explainability and Human Oversight

Explainability should answer a decision-relevant question. Global explanations describe average model behaviour; local explanations describe a particular forecast. Partial-dependence methods show average predicted response to a feature under assumptions that may be violated by correlated variables. Permutation importance measures performance degradation after disrupting a feature, but correlated predictors can share or obscure importance. Shapley-style methods allocate a prediction difference among features, yet their interpretation depends on the background distribution and feature-dependence assumptions.

Explanations are not causal proofs. A promotion variable may be predictive because it is associated with high-demand periods, but the explanation does not establish that changing the promotion would create the same demand increase. Analysts should distinguish prediction, association, and intervention.

Human oversight should include:

  • approval of target definitions, data sources, and feature availability;
  • review of forecasts during promotions, disruptions, and new-product launches;
  • override procedures with documented reasons and expiry dates;
  • monitoring for systematic errors across regions, customers, or product groups;
  • escalation rules for low confidence or out-of-distribution cases; and
  • accountability for decisions made using the forecast.

The human role is not simply to override an algorithm. It includes providing structured information the model cannot observe, challenging implausible outputs, and deciding how forecast uncertainty should be translated into inventory and service policies.

10. Drift, Monitoring, and Model Operations

Data drift is a change in the distribution of inputs, such as a new mix of products or changed promotion frequency. Concept drift is a change in the relationship between inputs and demand. Forecast drift or performance deterioration is observed when errors increase. Drift can be caused by competitor entry, channel migration, economic shocks, supply constraints, or changes in measurement systems.

A production monitoring system should track data completeness, feature ranges, missingness, prediction distributions, error by segment and horizon, bias, interval coverage, and business outcomes. Monitoring thresholds should distinguish random variation from meaningful deterioration. Retraining on a fixed schedule is not always appropriate: frequent retraining can incorporate temporary noise, while infrequent retraining can leave a model obsolete.

A champion–challenger process compares the deployed model with candidate alternatives on a rolling holdout. Model versioning must include training data windows, feature definitions, code, hyperparameters, evaluation results, and approval records. This creates reproducibility and supports auditability.

11. Applied Case: Illustrative Omni-Channel Retailer

Background

The fictional retailer Northstar Home supplies 2,400 products through stores and an online channel. It experiences weekly stockouts for fast-moving products and excess inventory for seasonal items. Its legacy process uses a seasonal naïve forecast plus planner adjustments.

Problem

Northstar wants a 4-week forecast by product and distribution centre. Available data include 30 months of sales, price, promotions, stock availability, delivery lead times, holidays, product category, and region. A major risk is that sales during stockouts do not equal unconstrained demand.

Analysis

The analytics team first defines the forecast origin and excludes information not known at that date. It flags stockout periods and includes availability as a feature. It creates lags at 1, 2, 4, and 52 weeks, rolling means based only on prior observations, holiday-distance variables, promotion indicators, and product and centre attributes. It evaluates a seasonal naïve model, regularized linear regression, gradient-boosted trees, and a global neural network.

The team uses rolling-origin validation with four-week horizons. It reports MAE and WAPE, but also simulated stockout cost, inventory holding cost, and 90% interval coverage. Random splitting is rejected because it would leak later seasonal information into training.

Approach and solution

The boosted-tree model performs best for products with regular promotions and rich history. A regularized linear model performs best for low-volume products, where the tree model is unstable. For intermittent items, a specialized count or intermittent-demand approach is retained. The production system therefore uses a model-selection policy by segment rather than one universal algorithm.

Quantile forecasts are generated for the boosted model. Planners see the point forecast, an uncertainty band, major contributing features, data-quality warnings, and the previous forecast revision. An override is permitted for documented events such as a confirmed retailer campaign or a known facility closure.

Outcome

In the illustrative pilot, the selected-model approach reduces validation MAE relative to the seasonal naïve benchmark and improves simulated service performance without simply increasing inventory. The most important operational improvement is not the algorithm alone: the retailer establishes stockout flags, temporal validation, drift monitoring, and a controlled planner-feedback process.

Learning points

  1. Observed sales can be censored by inventory availability.
  2. Segment-specific model selection can outperform a single enterprise-wide model.
  3. Business metrics should complement statistical accuracy.
  4. Forecast intervals and warnings improve decisions beyond a single number.
  5. Governance and data discipline are prerequisites for sustainable AI value.

12. Ethical, Legal, and Governance Considerations

Demand forecasting may affect worker schedules, supplier allocations, customer availability, and regional investment. Biased historical demand can reproduce unequal service levels. For example, a model trained on past stockouts may infer low demand in a community that was systematically underserved. Governance should therefore examine data provenance, missingness, segment performance, explainability, privacy, access controls, and retention.

Personal data should not be used merely because it is available. Where customer-level information is necessary, purpose limitation, minimization, lawful processing, security, and retention controls are required under applicable law and organisational policy. Vendor models should be assessed for documentation, data ownership, update practices, security, and audit access.

AI governance should assign roles for model ownership, validation, deployment, monitoring, incident response, and retirement. High-impact decisions require stronger review and human accountability. Automation should be proportionate to forecast confidence and consequence of error.

13. Contemporary Developments and Best Practices

Foundation-style time-series models, transfer learning, temporal fusion architectures, graph neural networks, and probabilistic deep-learning systems are active research areas. Graph methods can represent relationships among stores, products, routes, or facilities. Transfer learning may help cold-start products, but similarity assumptions must be tested. Generative AI can assist with scenario narratives and analyst interaction, yet generated explanations should not be treated as evidence of model causality.

Best practice is to:

  1. begin with a strong, transparent baseline;
  2. define the information set and prevent leakage;
  3. engineer features using only historical or genuinely known future information;
  4. use rolling-origin validation and decision-relevant metrics;
  5. compare local, global, statistical, and ML alternatives;
  6. quantify and calibrate uncertainty;
  7. monitor drift, bias, data quality, and business outcomes;
  8. retain human review for exceptional or high-consequence situations; and
  9. document the complete model lifecycle.

Chapter Summary

Machine learning and AI extend demand forecasting by learning nonlinear relationships, interactions, cross-series patterns, and external effects. Their effectiveness depends on disciplined feature engineering, especially lag construction and prevention of temporal leakage. Regularized linear models provide robust and interpretable baselines; tree ensembles are powerful for structured tabular data; neural networks can share information across many series and represent complex temporal relationships; and probabilistic methods quantify uncertainty for inventory and capacity decisions.

Statistical models remain essential benchmarks and may outperform complex models in stable or data-poor settings. Reliable evaluation requires rolling-origin validation, horizon alignment, suitable error metrics, and business-cost analysis. Overfitting, drift, poor calibration, biased data, weak explanations, and uncontrolled overrides can undermine an otherwise accurate model. Responsible deployment therefore combines technical monitoring, explainability, governance, and informed human oversight.

Key Terms

Temporal leakage: Use of information unavailable at the forecast origin.

Feature engineering: Transformation of raw data into model predictors.

Lag feature: A historical value of a variable used as a predictor.

Rolling feature: A statistic calculated over a trailing historical window.

Regularization: Penalty-based control of model complexity.

Ridge regression: Regression using an L2 coefficient penalty.

Lasso regression: Regression using an L1 coefficient penalty.

Random forest: An ensemble of randomized decision trees.

Gradient boosting: Sequential construction of models that reduce prior errors.

Neural network: A layered parametric function learned from data.

Global model: One model trained across multiple related demand series.

Probabilistic forecast: A forecast represented by a distribution or quantiles.

Calibration: Agreement between predicted uncertainty coverage and observed frequency.

Overfitting: Learning historical noise that fails to generalize.

Data drift: Change in the distribution of model inputs.

Concept drift: Change in the relationship between predictors and demand.

Explainability: Methods for understanding model predictions or behaviour.

Champion–challenger: A controlled comparison between a deployed model and alternatives.

Human oversight: Structured human review, intervention, and accountability in AI use.

Review Questions

Short Answer Questions

  1. What is temporal leakage, and why is it especially dangerous in demand forecasting?
  2. Distinguish ridge regression from lasso regression.
  3. Why should a seasonal naïve model be included in an ML forecasting evaluation?
  4. What is the difference between data drift and concept drift?
  5. Define calibration for a probabilistic forecast.

Long Answer Questions

  1. Explain how calendar, lag, rolling, commercial, and operational features can be engineered for a logistics forecasting problem. Include the main leakage risks.
  2. Compare random forests, gradient-boosted trees, and neural networks in terms of data requirements, interpretability, nonlinear modelling, and operational maintenance.
  3. Explain how rolling-origin validation should be designed for a four-week-ahead forecast and why random cross-validation is generally unsuitable.
  4. Discuss how probabilistic forecasts can support inventory and capacity decisions, including the limitations of prediction intervals.
  5. Develop a governance framework for deploying an AI demand-forecasting system in a multi-echelon supply chain.

Analytical / Application Questions

  1. A retailer has strong performance in training but poor performance in later validation periods. Diagnose at least four possible causes and propose a testing or remediation plan.
  2. A product frequently stocks out, and observed sales fall sharply during stockout weeks. Explain how you would redesign the data and model so that the forecast better represents demand rather than constrained sales.
  3. A boosted-tree model has the lowest MAE, but a regularized linear model produces better service levels and more stable forecasts for low-volume products. Recommend a deployment strategy and justify it using statistical and managerial reasoning.

Multiple Choice Questions with Answers

Question 1

Which feature construction correctly avoids including the target observation when predicting demand at time t?

A. A rolling mean using y_t through y_{t-6}

B. A rolling mean using y_{t-1} through y_{t-7}

C. A rolling mean using y_{t+1} through y_{t+7}

D. The realized promotion outcome from the end of period t

Correct Answer: B. A rolling mean using y_{t-1} through y_{t-7}

Question 2

What is the principal effect of an L1 penalty in lasso regression?

A. It forces every coefficient to increase

B. It removes the need for validation

C. It can set some coefficients exactly to zero

D. It guarantees unbiased forecasts

Correct Answer: C. It can set some coefficients exactly to zero

Question 3

Why are random train-test splits generally unsuitable for time-series forecasting?

A. They always produce too few observations

B. They can allow future information to influence training

C. They prevent the use of numerical variables

D. They cannot calculate MAE

Correct Answer: B. They can allow future information to influence training

Question 4

Which model is typically strongest for nonlinear interactions among promotions, prices, calendar variables, and lag features in tabular data?

A. A gradient-boosted tree ensemble

B. A seasonal naïve forecast only

C. A fixed moving average only

D. An unregularized intercept-only model

Correct Answer: A. A gradient-boosted tree ensemble

Question 5

A nominal 90% prediction interval is well calibrated when it contains approximately what proportion of realized outcomes over a representative evaluation sample?

A. 10%

B. 50%

C. 90%

D. 100%

Correct Answer: C. 90%

Question 6

Which metric remains in the original units of demand and penalizes large errors more heavily than MAE?

A. RMSE

B. WAPE

C. A correlation coefficient

D. A quantile level

Correct Answer: A. RMSE

Question 7

A change in the relationship between a promotion variable and demand is best described as:

A. Data drift only

B. Concept drift

C. Feature scaling

D. Calendar encoding

Correct Answer: B. Concept drift

Question 8

Why must observed sales during stockouts be treated carefully in a demand model?

A. They may understate unconstrained customer demand

B. They are always larger than demand

C. They contain no time information

D. They make all models linear

Correct Answer: A. They may understate unconstrained customer demand

Question 9

Which statement about model explanations is most accurate?

A. Feature importance proves that a feature causes demand

B. A local explanation describes a particular prediction but is not automatically causal

C. Explanations eliminate the need for validation

D. Correlated features never affect interpretation

Correct Answer: B. A local explanation describes a particular prediction but is not automatically causal

Question 10

What is a suitable purpose of a champion–challenger process?

A. To prevent all model updates

B. To compare a deployed model with alternatives using controlled, rolling evaluation

C. To replace business metrics with training loss

D. To hide model changes from users

Correct Answer: B. To compare a deployed model with alternatives using controlled, rolling evaluation

Dem& Forecasting Analytics
Chapter 7 of 14