Machine Learning · Time Series Regression

Inventory Demand Forecasting

End-to-end retail forecasting case study for predicting next-day product demand using historical sales, lag features, rolling statistics, and business signals. Designed to support replenishment decisions, inventory control, and short-term operational planning.

Retail ForecastingTime Series MLNext-Day HorizonDemand PlanningCase Study
2.80MAE for average absolute forecast error
3.54RMSE for larger error sensitivity
11.54%MAPE for relative business interpretability

On this page

Overview

Why this project matters

Demand forecasting is one of the most practical ML use cases in retail. Predicting next-day sales at store-item level helps operations teams move from reactive replenishment to data-driven planning.

Supports lower stock-out risk by identifying likely demand before shelves run empty.
Reduces excess inventory by aligning ordering decisions with expected near-term demand.
Connects model output to operational actions such as replenishment, promotion planning, and labor forecasting.
Stack

Implementation profile

The project is structured as a production-style forecasting workflow rather than a notebook-only analysis.

PythonData preparation, training, evaluation
Scikit-learnRegression modeling on tabular features
FastAPI-readyForecast serving and downstream integration
Business context

Why demand planning needs forecasting

Retail demand fluctuates across stores, items, seasons, promotions, and weekdays. Manual planning or simple averages fail to capture short-term changes that materially affect inventory performance.

Stock-out risk

Underestimating demand leads to missed sales, poor customer experience, and distorted store performance signals.

Overstock risk

Overestimating demand increases carrying cost, ties up working capital, and raises the likelihood of waste or markdowns.

Operational value

Reliable next-day forecasts improve ordering, promotion timing, and short-horizon labor planning for store operations.

Dataset

Data structure

Daily sales records include transactional and business attributes for each store-item pair.

Date: daily timestamp used for time-aware feature construction.
Entity keys: store_id and item_id identify each sales trajectory.
Target: next-day sales prediction at store-item level.
Business inputs: price and promo serve as operational signals.
Target framing

Prediction objective

The model uses only information available up to day t to predict demand for day t + 1. This makes the setup realistic and prevents hidden future leakage in features.

HorizonNext-day forecast
GranularityStore × Item
SplitChronological 80/20
RuleNo future leakage
Feature engineering

Temporal and business signals

Forecast accuracy depends heavily on the quality of time-aware features. This project combines calendar structure, historical demand memory, local smoothing, and business context.

Time features

day_of_week, month, week_of_year, day_of_month, year, is_weekend

Lag features

lag_1, lag_7, lag_14, lag_30 using past values only to preserve causal validity

Rolling features

rolling_mean_7, rolling_mean_30, rolling_std_30 to summarize local trend and volatility

Business features

price and promo alongside entity identifiers such as store_id and item_id

01

Sort chronologically

Order each store-item series by date so that all downstream features respect temporal direction.

02

Create lag memory

Use previous observations as structured memory of recent demand behavior at different time offsets.

03

Add rolling summaries

Smooth local noise and capture short-term level and volatility using moving statistics.

04

Preserve realism

Ensure every engineered feature could exist at inference time before the next day actually happens.

Modeling strategy

Tabular forecasting with time-aware validation

The project treats forecasting as a supervised regression problem over engineered tabular features. A tree-based regressor such as Random Forest works well when lag and rolling statistics already encode temporal structure.

Regression model trained on tabularized time-series features.
Chronological split instead of random split to simulate real deployment conditions.
Feature construction restricted to historical windows only.
Model profile

Operational modeling choices

ProblemRegression
BaselineNaive recent-demand estimate
CandidateRandom Forest Regressor
ValidationTemporal holdout
ServingSingle next-day request
GoalStable operational accuracy
Evaluation metrics

Forecast error from multiple angles

Different metrics emphasize different operational concerns. MAE captures average miss size, RMSE penalizes larger deviations more strongly, and MAPE helps explain performance in business-relative terms.

MAE

2.80 Average absolute error in forecasted daily demand.

RMSE

3.54 More sensitive to larger misses that can hurt operational planning.

MAPE

11.54% Relative error view for communicating forecast quality to business teams.

Feature importance

What drives the forecast

The model relies mostly on recent sales history. Strong lag dominance is expected in short-horizon forecasting where yesterday's and last week's demand often carry the most useful signal.

lag_7
62%
lag_14
13%
rolling_mean_30
11%
promo
10%
day_of_week
1%
rolling_mean_7
1%
week_of_year
0%
lag_1
0%
Interpretation

Reading the signal mix

The feature pattern suggests demand is primarily governed by short-cycle recurrence and recent local level, with promotions providing an additional but secondary business signal.

lag_7 dominance indicates strong weekly repetition in customer purchase behavior.
lag_14 reinforces that multi-week recurrence still matters for short-horizon estimation.
rolling_mean_30 contributes trend stabilization beyond single-day noise.
promo effect confirms that campaign activity changes demand enough to be operationally meaningful.
Forecast vs actual

Sample demand trajectory

This sample compares actual demand and predicted demand for a single store-item series. The goal is not perfect overlap, but stable alignment with level changes and short-term direction.

Store store_39 / Item item_46

Sample windowActual vs predicted
403020100
01-0201-0501-0801-1101-1401-1701-2001-2301-2601-30
Actual
Predicted
System architecture

How the forecasting workflow operates

The page presents the model as a reusable ML service: input features are prepared from recent history, transformed into the same training schema, scored by the regressor, and exposed through a simple API-facing interface.

1. Raw daily sales ingestionCollect date, store_id, item_id, sales, price, and promotion context from retail operations or batch exports.
2. Time-aware feature generationCreate lag and rolling features from historical windows only, preserving the realism of future unseen demand.
3. Model scoringSend the engineered feature vector into the trained regressor to obtain next-day demand prediction.
4. Operational consumptionExpose the forecast to replenishment workflows, dashboarding, or downstream planning systems through an API layer.
Business impact

How predictions translate into action

Forecasting is valuable only when it changes decisions. This project is designed as a decision-support layer for retail operations.

Replenishment

Use expected next-day demand to tune reorder quantities and prioritize store-item pairs most likely to run low.

Promotion planning

Estimate how promotions interact with local baseline demand to avoid under-preparation or excess stock build-up.

Operations planning

Support labor and short-horizon logistics by anticipating likely traffic and product movement at store level.

Live forecast tool

Generate a next-day demand prediction

Enter store-item identifiers, recent demand history, and business context to simulate a production-style forecast request.