Skip to Content
Course content

195: Demand Forecasting for Supply Chains

Click on the "Edit" button in the top corner of the screen to edit your slide content.

I've seen this happen a dozen times in warehouse management systems: a developer is asked to build a "demand forecast," and they treat it as a standard regression problem. They take the last two years of sales for something—let's say, high-end organic espresso beans—and run a simple linear model against a time index. On a scatter plot, it looks like a nice upward line. It feels intuitive. But in a supply chain, that approach is a recipe for either a bankrupt warehouse full of rotting beans or a series of angry phone calls from clients who are out of stock.

The Linear Trap and the Myth of the Average

The naive approach usually looks like this in R: you load your data into a data frame and call lm(sales ~ date_index). The problem is that linear regression assumes each data point is independent. In supply chain demand, that's almost never true. If you sold a massive amount of espresso beans last Tuesday, it’s highly likely you’ll sell a significant amount this Tuesday. There is autocorrelation—the data remembers where it was.

# The "Naive" way - Avoid this for supply chains
model_naive <- lm(units_sold ~ time_index, data = coffee_data)
forecast_naive <- predict(model_naive, newdata = future_dates)


When you use a linear model, you're essentially forecasting the "average trend." But supply chains don't live in the average. They live in the peaks and valleys. If your espresso beans peak every December for the holiday season, a linear model will under-forecast in December (leading to stockouts) and over-forecast in January (leading to wasted capital). You're ignoring seasonality and the stochastic nature of demand, treating a rhythmic pulse like a straight line.

Moving to State-Space and the fpp3 Ecosystem

If we're going to do this right, we need to stop thinking about "regression" and start thinking about "time series." I always steer my team toward the fpp3 suite (which includes tsibble, feasts, and fable). Instead of a flat data frame, we use a tsibble, which explicitly understands that the data is indexed by time. This allows us to use ETS (Error, Trend, Seasonality) models.

An ETS model doesn't just look at the slope; it decomposes the signal. It asks: "How much of this is a long-term trend? How much is a repeating seasonal pattern? And how much is just random noise?" For our coffee beans, an ETS model can recognize that every Q4 sees a 30% bump, regardless of whether the overall yearly trend is growing or shrinking.

library(fpp3)

# The "Better" way - Using a tsibble and ETS
coffee_ts <- coffee_data %>% 
  as_tsibble(index = date)

fit <- coffee_ts %>%
  model(
    ets = ETS(units_sold)
  )

forecast_better <- fit %>%
  forecast(h = "3 months")


The trade-off here is complexity. You're no longer looking at a simple y = mx + b equation. You're dealing with smoothing parameters. But the payoff is a forecast that actually mirrors the reality of a warehouse. You get a "fan chart" of uncertainty rather than a single line, which is critical for calculating safety stock.

When the Sophisticated Model Breaks

Now, I should warn you: don't treat ETS or ARIMA as magic. These models are backward-looking. They assume the future will behave like a weighted version of the past. If your coffee supplier suddenly goes bankrupt or a new competitor opens a shop across the street, your fable model will confidently predict demand based on a world that no longer exists.

I usually tell my colleagues that the model provides the baseline, but the human provides the "overlay." If you know a massive marketing campaign is hitting next month, you manually adjust the model's output. The goal isn't to replace the supply chain manager; it's to stop them from having to do the tedious math of seasonality by hand so they can focus on the anomalies the model can't see.




📋 Practical Task

Implementing an Espresso Bean Demand Forecast with MAPE Validation

You have been provided with a dataset coffee_sales_data containing two years of weekly sales for "Artisan Roast Coffee - 1kg Bag". Your goal is to compare a naive seasonal forecast against an automated ETS model and determine which one is more reliable using Mean Absolute Percentage Error (MAPE).

Requirements:

  • Convert the raw data frame into a tsibble.
  • Create a training set (first 18 months) and a test set (last 6 months).
  • Fit two models to the training set: a SNAIVE (Seasonal Naive) model and an ETS model.
  • Forecast the test set period for both models.
  • Calculate the MAPE for both forecasts to identify which model more accurately predicted the actual sales.

Expected Output: A comparison table showing the MAPE for both the SNAIVE and ETS models, and a short print statement indicating which model should be deployed to the production supply chain system.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.