Data Science in Supply Chain: A Demand Forecasting Test
Data science in supply chain management starts with demand forecasting: how much will we sell, and how much stock should we hold against being wrong? This article tests both on 108 months of real monthly sales data. We compare three forecasts on unseen months, then turn the forecast error into a safety stock and check whether it delivered the service level it promised. The honest result: the simplest forecast won, and the safety stock fell short of its target. Computed with pandas 3.0.5 and NumPy 2.5.3.

The data
The series is monthly car sales in Quebec from January 1960 to December 1968, 108 months, from a public time-series collection. It is not a company’s own product data, but it is real demand with a strong seasonal pattern, which makes it a good stand-in. Monthly sales ranged from 5,568 to 26,099 cars with a mean of 14,595. Sales peak in spring (May average 20,884) and trough in autumn (September 10,140).
import pandas as pd, numpy as np
d = pd.read_csv('monthly-car-sales.csv')
d.columns = ['month', 'sales']
train, test = d.iloc[:-24], d.iloc[-24:] # hold out the last 24 months
last_month = np.repeat(train.sales.iloc[-1], 24)
same_month_last_year = np.array(train.sales.iloc[-12:].tolist() * 2)
mae = lambda f: np.abs(f - test.sales.values).mean()Three forecasts, tested on unseen months
| Forecast | Mean absolute error | Average error % |
|---|---|---|
| Same as last month | 3,683 | 18.9% |
| Linear trend times seasonal profile | 2,422 | 14.3% |
| Same month last year | 1,541 | 8.3% |
Repeating last month is badly wrong because it ignores seasonality (3,683 cars, 18.9%). A trend-times-season model fitted on the training years did better (2,422) but still lost to the simplest seasonal rule, repeating the same month of the previous year (1,541 cars, 8.3% error). Our trend model slightly over-projected growth: its fitted trend added about 104 cars a month, while actual sales in the first test year were 0.9% below the last training year. Always compare a complex forecast with a seasonal baseline first.
From forecast error to safety stock
Safety stock is the extra inventory you hold so that demand above forecast does not cause a stock-out. A standard approach sets it at a number of standard deviations of forecast error (z) above the forecast. We measured the error of the same-month-last-year forecast on the training years: mean +1,090 cars, standard deviation 1,716. Then we applied z values for 90%, 95% and 99% target service levels to the 24 test months and counted how often stock actually covered demand.
| Target service | z | Extra stock per month | Months fully covered (of 24) | Units short in total |
|---|---|---|---|---|
| 50% | 0 | 0 | 46% | 26,606 |
| 90% | 1.28 | 2,197 | 83% | 7,881 |
| 95% | 1.65 | 2,832 | 88% | 5,537 |
| 99% | 2.33 | 3,999 | 92% | 2,631 |
Every row fell short of its target: the 90% policy covered 83% of months, the 95% policy 88% and the 99% policy 92%. The reason is that the error spread measured on the past did not match the future. Demand in the second test year was 9.9% above the first, a shift the forecast could not know about. This is common in practice: safety stock formulas assume stable, normally distributed errors, and real demand changes. Raising z reduced the shortage (from 26,606 units at z = 0 to 2,631 at z = 2.33) but each step cost more stock, and no step reached the target.
What to do with this
Re-estimate forecast error regularly and on recent data, monitor service level rather than trusting the formula, and treat the target as a goal to verify. Real supply chains add lead-time variation, multiple products and costs for holding versus shortage, which turn the question into an optimisation problem. The same forecasting skills appear in our time series analysis guide and data pipeline optimisation for the data plumbing; for a route-planning example see data science in logistics and for retail demand data science in retail. The statsmodels time series documentation lists more forecasting models.
Limits of this analysis
One series from the 1960s, 24 test months, a single stock-keeping unit with no lead time or costs, and a safety-stock rule applied without lead-time variation. The service levels are measured on only 24 months, so each percentage is a multiple of about 4 points.
FAQ
How is data science used in supply chain management?
For demand forecasting, inventory and safety-stock planning, route optimisation, supplier risk and predictive maintenance. This article covers forecasting and safety stock.
What is the best demand forecasting method?
It depends on the data. Here repeating the same month of last year beat a trend-and-season model on 24 unseen months. Always test a simple seasonal baseline.
How is safety stock calculated?
As z times the standard deviation of forecast error, where z comes from the service level (1.28 for 90%, 1.65 for 95%, 2.33 for 99%).
Why did my safety stock not meet the service level?
In our test demand shifted after the error was measured, and the formula assumes stable errors. Re-measure error often and check actual service.
