AI Hints
Home›Data Science Tutorial›Forecasting in Practice
Data Science · Lesson 47 of 101

From Forecast to Decision

How much should we order?.

⏱ 2 min read▶ Video at 1:19:54🎓 Free
Watch this lesson in the Data Science courseWatch on YouTube ↗Full Data Science course

The forecast says that you'll sell four hundred and twenty muffins tomorrow. So should you bake four hundred and twenty? Most people would say yes. And most people would be wrong.

From Forecast to Decision
From the video: From Forecast to Decision
  • The forecast says 420
  • Should you bake 420?
  • Most people would be wrong

The newsvendor problem

A muffin costs one dollar thirty, and sells for four fifty. So running out costs you more than having extras left over. We test each possible order size, across thousands of simulated days, and pick the most profitable. Then we compare that with a neat classic formula. Run it. The best order isn't four hundred and twenty. It's around four hundred and sixty. And that one line formula gets almost the same answer. When the loss from selling out is bigger than the loss from waste, order above the forecast. A forecast tells you what's likely. The costs tell you what to do.

newsvendor.pypython
import numpy as np

rng = np.random.default_rng(0)
demand = rng.normal(420, 70, 100000).clip(0)
cost, price = 1.3, 4.5

def profit(order):
    sold = np.minimum(demand, order)
    return (sold * price - order * cost).mean()

best = max(range(300, 601, 10), key=profit)
print(f"Order the average (420): ${profit(420):,.0f}")
print(f"Best order ({best}): ${profit(best):,.0f}")
print(f"Newsvendor rule: {np.quantile(demand, (price - cost) / price):.0f}")
Output
Order the average (420): $1,218
Best order (460): $1,236
Newsvendor rule: 459

Decisions need costs

This idea applies far beyond muffins. How many staff to roster, how much stock to hold, and how many servers to run. In each case, ask what it costs to be too high, and what it costs to be too low. If the costs are equal, aim for the forecast. If not, lean towards the cheaper mistake. Many companies throw this value away by using just one number.

Too high costs?waste, idle staff
Too low costs?lost sales, queues
Lean to the cheaper mistakenot the average
Use the full rangenot one number

Summary

The best decision is rarely the average. Your forecasts now create real value. Next, let's put some classic probability to work.

Key takeaways
  • Forecasts aren't decisions
  • Weigh the cost of each mistake
  • Order above if selling out costs more
Next up: Modelling Arrivals — the maths of busy mornings