ENGINEERING CASE 06 / Analytics

Demand and Sales Forecasting: From History to a Plan

Train the model on history. Check against the standard. Link demand, sales and inventory.

Modelled engineering case. Developed by ITTECHE to analyze architecture and solutions. Company, educational data and calculations; the confirmed result of client implementation is not declared.

TASK

Build a demand forecast at the product and warehouse level, compare it with a simple standard, calculate the sales scenario in rubles and prepare a replenishment draft. Each recommendation requires data version, horizon, validation error, price, discount, availability, expected delivery, and reason for manual revision.

Machine LearningBacktestingInventory Planning
Go to demo
A shelf with boxes next to voluminous demand history columns, semi-transparent forecast values and a replenishment tray.
Conceptual illustration of the solution.
01 / CONTEXT

From the business task
to a verifiable solution.

In a model trading company, the buyer plans replenishment based on the sales of the last weeks. Some goods are growing, some are sold in rare large orders. Zeros could mean no demand, a closed store, or out of stock. The average sales rate alone confuses these situations and poorly explains the next purchase.

weeks of synthetic history
24
three checks for four weeks
3 × 4
weeks of educational forecast
8
different types of demand
2
  1. 01

    Restore the observed process

    Sales, returns, balances, availability and calendar are reduced to one week and units. Shortage periods are marked separately; lost demand is not guessed from zero sales.

  2. 02

    Train and compare

    Next to two simple methods, regression with regularization is trained. Based on the previous history, five coefficients are estimated: level, trend and three cycle corrections. The structure and penalty are fixed in advance.

  3. 03

    Check for future periods

    The story is cut off at several points. The model uses only information known at the forecast date; the result is compared with subsequent observations.

  4. 04

    Convert volume to sales

    The quantity forecast is linked to availability and selling price by product and channel. Promotions, discounts, returns and cancellations are set explicitly; the total in rubles is checked against the weekly lines.

  5. 05

    Create a replenishment plan

    The forecast for the protection period is compared with available stock, supplies and commitments. Batch, budget and warehouse restrictions are discussed separately with the buyer.

02 / INTERACTIVE DISCUSSION

How are demand, sales and inventory related?

Two synthetic series of 24 weeks and three methods: loop repeat, loop with shift and trained ML regression. Each of the three checks builds a four-week forecast using only the previous history. The model is retrained on each slice.

Educational product
Method

Where AI fits in and what it learns

The ML model selects five coefficients based on the history of the selected product: a base level, a trend, and three adjustments for the phases of a four-week cycle. This is regression with regularization, one of the machine learning methods. The coefficients are calculated from the data; ready-made answers are not included in the page.

In each test, the model is trained on only weeks 1–12, 1–16, or 1–20 and predicts the next four weeks. For release in weeks 25–32, it is retrained on all 24 observations. Change the product - the trained coefficients, forecast and errors will change.

MAE ML: 1.25 pcs/week; standard: 3; cycle with shift: 1. ML is better than the standard, but inferior to the shift method. You need to choose a method based on verification.

What the model learned

Full release model shown: 24 weeks, five coefficients. Feature structure and penalty λ = 0.1 are set in advance and are not selected according to test weeks. A free member is not penalized. The forecast is rounded to integers and limited from below to zero before errors are calculated.

Basic level
21.0987
Trend · week index / 24
17.1895
Second phase amendment
5.4323
Third phase amendment
1.7769
Phase Four Amendment
8.4495

Formula: base level + trend coefficient × week index / 24 + current phase correction. The index starts from zero; the first phase is the basic one. Training minimizes the sum of squared errors with a penalty on the coefficients.

Download trained models and validation JSON

This is a small ML training example on synthetic data. The four-week cycle is predetermined; no annual seasonality found. Prices, promotions, and demand response to discounts are not included in the model. The neural network and language model are not used here. The result does not confirm accuracy on the real catalog or on weeks 5–8 of the horizon.

Check in weeks 13–24: three consecutive episodes of four weeks
MethodMAE, pcs./weekWAPEDisplacement, pcs./week
Repeat cycle37.9%-3
Cycle + level shift12.6%0
ML regression1.253.3%-1.25

MAE—mean absolute error; less is better. The bias is calculated as the forecast minus the fact. WAPE is the sum of absolute errors divided by the sum of actual errors; it can be higher than 100%, but if the sum is zero, the fact is not determined.

Educational history and eight future meaningsSolid line—24 observations. Dotted line - forecast for weeks 25–32. All values ​​are available in tables.6001122432
History: weeks 1–24Forecast: weeks 25–32
Next forecast release on full available history
Week2526272829303132
Forecast, pcs.3844414941474452

Sales forecast: pieces → rubles

Training scenario: all forecast volume is available and sold at one price, returns and cancellations are zero. Set the price and discount for the next eight weeks. Sales amount = quantity × price after discount.

Price before discount
Discount
Volume for 8 weeks
356 units
Price after discount
1,000 ₽
Sales in 8 weeks
356,000 ₽
Sales at a given price and full availability of goods
WeekVolume, pcs.Price after discount, ₽Sales amount, ₽
25381,00038,000
26441,00044,000
27411,00041,000
28491,00049,000
29411,00041,000
30471,00047,000
31441,00044,000
32521,00052,000
Total356—356,000

Changing the price or discount here only changes the monetary scenario. The response of demand to price is not modeled. This is a sales revenue scenario, not a profit or cash flow schedule: costs, expenses and payment terms are not specified. The calculation is carried out in kopecks; the price after the discount is rounded to the nearest penny before multiplying by volume. The historical audit above estimates quantities, revenue accuracy has not been separately verified.

From forecast to draft replenishment

Training conditions: 70 units in stock, 10 units reserved; safety stock is set manually - 12 pcs. The order is reviewed once a week. The plan covers delivery time plus one week until next review.

Delivery time
Protection period
3 weeks
Demand for the period
123 units
Stock item
100 units
Draft order
35 units

Target stock: 123 + 12 = 135 pcs. Stock item: 70 + 40 − 10 = 100 pcs. Order: max(0, target stock − position).

This is a calculation based on prepared data, without sending an order. The safety stock is not derived from the probability of shortage; receipt dates within a period, batches, transport and warehouse capacity require a separate model.

How the forecast was checked without access to the future

Release points: after weeks 12, 16 and 20. For each, only data up to and including the cutoff is used; forecast for the next four weeks. The four-week windows tested do not overlap. The future eight values ​​are recalculated from all 24 observations; their error is still unknown.

Checking the chosen method: 12 predictions before the fact is revealed
History up to a weekCheck weekForecastFactForecast - fact
12132830-2
12143435-1
12153133-2
12163841-3
161732320
16183840-2
16193536-1
16204243-1
20213536-1
202241410
20233839-1
20244647-1

Testing in the demo is limited to a four-week horizon. For a real replenishment policy, the aggregate demand for its protection period is additionally checked; One week's MAE does not replace this test.

History and formulas of the two methods

All observations are synthetic, chosen to explain the behavior of the methods. The four-week cycle is predetermined and is not a found annual seasonality. The standard repeats the last four values. The second method adds the difference in the means of the last two four-week blocks to each subsequent forecast block; the result is rounded to integers and bounded below by zero.

Horizons 1–4 receive one shift, 5–8 two. There are no future observations in the formula. The parameters of safety stock and balances are specified separately; probability intervals are not calculated here.

All 24 observations of the selected series
WeekQuantity, pcs.
120
228
324
431
524
629
727
835
926
1034
1130
1237
1330
1435
1533
1641
1732
1840
1936
2043
2136
2241
2339
2447
03 / ARCHITECTURE

From measurement -
to an explicable action.

  1. 01

    ERP and sales

    History of SKU × warehouse × channel × week: quantities, prices, discounts, returns, cancellations, shortages and deliveries.

  2. 02

    Features and versions

    Prices, calendar and promotions in versions known at the date of calculation; logs and units without leakage of the future.

  3. 03

    Training and Prediction

    Retraining ML at each time slice, comparing with standards and saving coefficients. In the educational interactive, only the trend and the specified cycle are trained; prices and promotions are the tasks of the future pilot.

  4. 04

    Inventory planner

    Protection period, stock position, delivery terms and confirmation by the purchaser.

Infrastructure, storage and integration periods are clarified during the survey. The event's identifier, time, source data, model version, and decision are saved.

04 / ENGINEERING SOLUTIONS

The difficulty lies in the conditions
errors and verification.

01

Sales don't always equal demand

It’s easy to mistake a week without a product for a week without demand and fix the error in the next plan.

Solution
Link a row to availability history. Exceptions and methods of handling deficits should be agreed upon separately; the unknown cannot be converted into a reliable estimate.
How to check
Control periods for lack of goods, warehouse closures and returns. Demand forecast and observed sales forecast are assessed as different problems.
02

Volume and cash sales are verified separately

An increase in price can increase the amount of sales for the same quantity, while shortages, discounts and returns can reduce it. Accuracy in units does not prove accuracy of revenue.

Solution
Count sales based on available volume and price after discount, coordinating the processing of returns and cancellations. For a working forecast, take into account channels and check price scenarios; elasticity of demand is assessed separately.
How to check
The weekly totals add up to the grand total. The price and discount in the educational interactive do not change the volume. In the pilot, quantity and ruble forecast errors are assessed separately; revenue does not replace profit.
03

Checking without knowing the future

Randomly shuffling weeks or using the final adjusted promotional plan improves the report, but not the working forecast.

Solution
Capture temporary snapshots and check several successive horizons. Signs and transformations are calculated only from the history available for the slice.
How to check
Future observation change test: A previously issued forecast should not change. The verification horizon must correspond to the replenishment task.
04

Machine learning must earn a place in the plan

The trained model may lose to a simple rule. The ML name alone does not confirm accuracy.

Solution
In the demo, regression coefficients are trained separately on each slice. Metrics from the three methods, full release coefficients, and JSON with slice models and test predictions are available side by side.
How to check
On a regular MAE series: standard 3, cycle with shift 1, ML 1.25 pcs./week. On rare orders, ML loses to the standard and is blocked. These are the results of a synthetic example only, with no promise of improvement on client data.
05

Different products - different models

A method that is useful for regular growth can create false sales in a long string of zeros.

Solution
Separate regular and intermittent demand. Compare the seasonal standard, statistical models and trait-based models on the same sections; evaluate new products separately.
How to check
MAE in units, aggregated error, bias and results by segment. Good company-wide results should not hide the failure of individual groups.
06

Forecast and order - different solutions

Even an accurate forecast does not specify the batch size: there is stock, supplies, reserves, delivery time and shortage price.

Solution
Separate demand calculation from inventory policy. For a working solution, check the error distribution over the protection period, vendor restrictions, and the selected service level.
How to check
Historical reproduction of the policy under the same conditions: availability, shortfalls, average inventory and turnover. The percentage of error is not reported as a percentage of savings.
05 / CHECK AND PILOT

What needs to be confirmed
on real data.

Input quality

Completeness of balances and sales, units of measurement, history of SKU changes and signs of shortage. For each exception, the reason and decision of the data owner is stored.

Forecast quality

Checking by time and horizons, comparison with the standard, offset and errors by segments. For a probabilistic forecast, the actual coverage of the intervals is additionally checked.

Sales forecast quality

Reconciliation of prices after discounts, available volume, returns and cancellations by channel. Separate time checking of errors in rubles and reconciliation of weeks with the total; the fact of the future price is not substituted into the past forecast.

Plan quality

The first pilot forms recommendations next to the existing process. The effect is assessed on comparable demand and restrictions; The final purchases are confirmed by an employee.

Path from survey to transmission

  1. 01

    Data and Business Rules

    Series granularity, definitions of demand and shortage, decision horizon and basic process.

  2. 02

    Training and backtesting

    Standard, model training on each slice, saving parameters, segments and candidate selection criteria.

  3. 03

    Sales and replenishment

    Price and discount scenarios, sales in units and rubles; inventory position, deliveries and exception review.

  4. 04

    Pilot and observation

    Reconciliation with the buyer, drift control, model revision regulations and process transfer.

This is a sequence of work, not a promise of a deadline or budget. The assessment comes after checking the source data and integrations.

06 / BORDERS

Where a solution is required
a different approach.

  • 24 school weeks do not confirm annual seasonality. A real object needs a history that covers important cycles and process changes.
  • Promotions, new products, replacements and rare large orders require separate verification. Accuracy on prepared rows is not automatically transferred to the catalog.
  • The training safety stock is manually set and does not meet the promised service level. Orders are not sent to the supplier from the page.
FROM SCRIPT TO YOUR OBJECT

Let's start with the data
and acceptance criteria.

For the first discussion the following are useful:

  • History of sales, returns, cancellations and availability by product, warehouse and channel.
  • History of prices and discounts; future prices and promotions in versions known at the forecast date.
  • Balances, reserves and expected deliveries with date and quantity.
  • Delivery times, batch rules and those responsible for sales and purchasing.
Discuss a similar project View the direction of work ↗All cases ↗