Skip to main content

Inventory Forecasting

Stop guessing reorder points - let order history tell you when to stock up

The Problem

Last month's sales are not a forecast

Most retailers manage inventory using rules of thumb: order what you sold last month, add a buffer, repeat. This approach is invisible when demand is flat and catastrophic when it is not. It does not tell you that laptop sales will spike 78% in October. It does not tell you that the 300 units you ordered in September will sell out in the first two weeks of October. It does not tell you anything about November until October has already happened.

The data to predict this already exists in the order history. Every sale is a timestamped signal. A demand forecasting model reads those signals, extracts the trend, identifies the seasonal pattern, and produces a prediction with confidence intervals: here is how many units category X will likely sell next month, and here is the reorder quantity that keeps you in stock with 95% confidence.

95%
understock for Laptops in Oct 2025
Rolling mean predicted 252 units - actual was 490
+207
units Prophet flags 8 weeks early
Oct 2026 forecast vs flat rolling mean projection
18mo
of TechHeaven order history
Jan 2025 - Jun 2026 across 15 categories

This playbook builds both a rolling mean baseline and a Prophet demand model on TechHeaven's 18 months of order history. The Q4 2025 spike - 78% above the monthly baseline in October - is the central test case. The rolling mean cannot predict it. Prophet learns the seasonal pattern and forecasts the next Q4 cycle 8 weeks before it happens.

The Data

What the notebook trains on

Two JSON files loaded directly from the TechHeaven public repository. No database, no local setup, no API key required - the notebook fetches the data at runtime and builds the models from scratch.

Orders5,000

4,250 completed + processing orders used (500 cancelled and 250 pending excluded). Order date range: Jan 2025 - Jun 2026.

Categories15

Laptops, Memory, Smart Home, Audio, Networking, Mobile Accessories, Monitors, Wearables, Drives, Mice, Keyboards, Cameras, Accessories, Components, Printers.

Training horizon18 months

One complete Q4 seasonal cycle observed. Sufficient for annual seasonality detection with Prophet yearly_seasonality=True.

AggregationMonthly

Monthly units sold per category. Category-level aggregation produces 18 data points per series - sparse categories filled with zero demand months.

The Q4 spike

October 2025: 2,354 units across all categories - 78% above the baseline average of 1,324 units/month. November 2025: 2,018 units - 53% above baseline. This two-month spike is the signal both models must handle. A rolling mean smooths over it. Prophet learns from it.

The Approaches

Rolling mean baseline vs. Prophet

Both models train on the same 18-month monthly demand series. The difference is in what each model can represent: a rolling mean averages the recent past, a Prophet model decomposes the series into trend, seasonality, and residual.

Rolling Mean (Baseline)
pandas rolling()Low complexity
How it works
Predicts next month by averaging the previous N months. No explicit trend or seasonality component. Simple to compute, easy to explain to non-technical stakeholders.
Strength
Fast, interpretable, no model training required. Accurate on flat, stable demand. The method most retailers use today, explicitly or implicitly.
Weakness
Cannot distinguish seasonal patterns from trend. Predicts flat demand ahead of a Q4 spike. Catches up only after the spike is already over.
Prophet (Meta)
prophet (Meta open-source)Medium complexity
How it works
Decomposes the time series into trend + seasonality + residual using a Fourier series for the seasonal component. Fitted on all 18 months. Forward forecast extrapolates both trend and seasonal pattern.
Strength
Encodes the Q4 seasonal pattern after observing it once. Forward forecast shows the October 2026 spike before it happens. Includes 95% confidence intervals for reorder buffering.
Weakness
Requires 12+ months of data for reliable annual seasonality. Fitting 15 models takes ~30 seconds. Hyperparameters (changepoint_prior_scale, seasonality_prior_scale) affect fit quality.

Results

The Q4 test: where rolling mean fails

The notebook runs both models in-sample on 18 months of history, then generates a 6-month forward forecast. The Q4 spike is the central test: a model that cannot predict it is not useful for purchasing decisions. A model that can gives a buyer 8 weeks of lead time to build stock.

October 2025 - Laptops
Rolling mean
Predicted 252 → Actual 490 (+95% miss)
Understocked by 238 units. Re-ordering takes weeks.
Prophet
Captures the spike in-sample
annual seasonality component peaks at month 10
November 2025 - Laptops
Rolling mean
Predicted 330 → Actual 446 (+35% miss)
Understocked by 116 units. Re-ordering takes weeks.
Prophet
Rolling mean recovers partially by including October data
still 35% short
October 2026 forward forecast - Laptops
Rolling mean
Predicts flat: 294 units/month
No seasonal awareness. Buyer orders for July, not October.
Prophet
Prophet forecasts 501 units (+207 vs rolling mean flat). Buyer acts in August.

The buyer's timeline

A buyer using rolling mean orders normal stock in August based on the July average. October arrives, laptops sell out in two weeks, and an expedited reorder costs 15-30% more with 4-6 weeks of stockout. A buyer using Prophet sees the October forecast in August, places the larger order in time, and captures the full Q4 revenue. The forecasting cost is a one-time 30-second model fit. The stockout cost is permanent lost revenue.

Core Concepts

How each piece works

Time Series Decomposition

A time series is any sequence of measurements over time. Demand forecasting decomposes it into three components: trend (long-term direction), seasonality (repeating annual or weekly pattern), and residual (unexplained noise). A rolling mean captures none of these explicitly - it averages them together. Prophet fits each component separately, which lets it extrapolate each one independently into the future.

TechHeavenTechHeaven Laptops: trend is flat (297 units/month average over 18 months). Annual seasonality peaks at month 10 (October) by approximately +80%. Residual is the month-to-month noise around those two components. Prophet separates these three signals; rolling mean cannot.

Prophet Seasonality (Fourier Series)

Prophet represents annual seasonality as a sum of sine and cosine terms at different frequencies (Fourier series). By default, Prophet uses 10 Fourier terms for yearly seasonality, giving it enough flexibility to model complex seasonal shapes while remaining smooth. The Fourier terms are fitted to the historical data during model training. Once fitted, they can be extrapolated forward indefinitely.

TechHeavenAfter fitting on 18 months of TechHeaven data, Prophet's yearly seasonality component peaks sharply at month 10 and month 11. This is encoded in the Fourier coefficients. When generating the October 2026 forecast, Prophet applies the same seasonal shape it learned from October 2025 - even though October 2026 has not been observed.

Rolling Mean as a Baseline

A 3-month rolling mean predicts next month by averaging the 3 preceding months. It is a 1-step-ahead forecast: at each time step, it uses the 3 months immediately before the target month (not including it). This is what a buyer does intuitively: "we sold 250, 270, and 290 last three months, so let's order 270." It works when demand is stable and fails when it shifts.

TechHeavenFor Laptops in October 2025, the rolling mean uses July, August, and September data: (240 + 266 + 250) / 3 = 252 units. Actual October: 490 units. The rolling mean has no information about the October seasonal pattern because it only looks back 3 months, not 12.

Confidence Intervals and Safety Stock

Prophet outputs a point estimate (yhat) and uncertainty bounds (yhat_lower, yhat_upper at 95% confidence). The uncertainty grows further into the future. The reorder table uses the upper 95% bound as the base order quantity, then adds one month of safety stock at the point estimate. Ordering to the upper bound protects against demand coming in above the forecast; safety stock covers supplier lead time.

TechHeavenLaptops July 2026: Prophet point estimate 222 units, upper bound 229 units. Reorder quantity: 229 (upper bound) + 222 (safety stock at 1x lead time) = 451 units. If demand comes in at 280 (above point estimate but below upper bound), the order still covers it.

Monthly vs. Weekly Aggregation

Weekly aggregation produces more data points (78 weeks vs 18 months) but introduces alignment noise, day-of-week effects, and sparse data for small categories. Monthly aggregation is more stable, aligns with how buyers make purchasing decisions, and works better with Prophet's yearly_seasonality at this data scale. The tradeoff: monthly forecasts cannot detect within-month demand shifts.

TechHeavenTechHeaven has 15 categories. The smallest (Printers) has 410 units total over 18 months - about 23 units/month. At weekly granularity, most weeks have 0-8 units. At monthly granularity, it has 11 non-zero months with mean 37 units. Prophet fits meaningfully on monthly data; weekly data would produce near-zero forecasts for several consecutive weeks.

Architecture

Production forecasting pipeline

The notebook demonstrates forecasting in batch. In production, the pipeline runs on a schedule - typically weekly - to keep models current with the latest order data and trigger purchasing alerts before stock runs low.

Weekly batch job
Runs every Monday morning
  1. 1Fetch order history from the ecommerce database
  2. 2Aggregate by month and category, fill missing months with zero
  3. 3Fit one Prophet model per category (15-30 seconds total)
  4. 4Generate 6-month forward forecast per category
  5. 5Compute reorder quantity: upper 95% CI + safety stock
  6. 6Write results to a dashboard or send a purchasing report
Alert integration
Triggered when stock falls below reorder point
  1. 1Compare current stock level against reorder quantity from the forecast
  2. 2Flag categories where stock < reorder quantity
  3. 3Generate a draft purchase order for the buyer to review
  4. 4Send alert via Slack, email, or ERP integration
  5. 5Log purchase decision and actual demand for model improvement
  6. 6Retrain models monthly as more seasonal cycles accumulate
Integration points
Data source
Bagisto, Shopify, WooCommerce, any SQL database
Model
Prophet (per-category), optionally ARIMA or LightGBM for higher volume
Output
Purchase order draft, Slack alert, Google Sheets, ERP write-back
Monitoring
Forecast accuracy (MAPE per category), stockout rate, overstock days

Business Applications

Ecommerce / Retail
Seasonal demand forecasting is the primary use case. A retailer with 12+ months of order history can run Prophet per product category and know in August that October demand will spike. Reorder recommendations with confidence intervals replace gut-feel purchasing decisions with data-driven ones.
Manufacturing / Distribution
Component and raw material procurement follows the same logic. A manufacturer who ships more in Q4 needs to order materials in August, not October. Monthly demand forecasting at the component level prevents production bottlenecks caused by late procurement.
SaaS / Subscription
Seat and license forecasting, server capacity planning, and support staffing all benefit from time series models. If signups spike every January after the holiday break, Prophet encodes that pattern and predicts it forward. Infrastructure teams can provision capacity before the spike, not after.
Professional Services / Staffing
Demand for consulting engagements, contract workers, and project-based services follows seasonal patterns tied to budget cycles and fiscal quarters. Forecasting workload 2-3 months ahead enables proactive hiring and subcontractor sourcing rather than reactive scrambling.

Run the notebook

The Jupyter notebook builds both models from scratch on 18 months of TechHeaven order history. Rolling mean in-sample comparison, Prophet fit on 15 categories, decomposition charts, 6-month forward forecast, and a reorder point table with 95% confidence interval logic. No API key required.

Open in Colab