
Lecture 5 - Management Science
Operations Director’s Crisis:
“Last Christmas, we ran out of PlayStation 5s but had 500 unsold fitness trackers. We lost €2M in missed sales and clearance losses. How do we predict what customers will actually buy?”
Question: Why can’t we just order the same as last year?
Reality: Large retailers process several thousand orders per hour. Each stockout basically means lost revenue + unhappy customers.
Look at this daily sales data. What patterns do you see?

Time series can often be decomposed:
\[Y_t = T_t + S_t + R_t\]
Where:
How do the components combine?
Additive Model \[Y_t = T_t + S_t + R_t\]
Multiplicative Model \[Y_t = T_t \times S_t \times R_t\]

Here: Sales = Trend + Seasonality + Random Noise
Question: How do we separate signal from noise?

Which forecast would you trust more?
Simple Moving Average
Weighted Moving Average
Recent data often predicts the future better than old data!
Not too simple, not too complex
\[\text{Forecast}_{t+1} = \alpha \times \text{Actual}_t + (1-\alpha) \times \text{Forecast}_t\]
Think of \(\alpha\) like: How much do you trust the latest data point?
Simple smoothing assumes the data is flat. What if it’s not?

Track TWO things separately: Level and Trend
Why This Works:
Think of driving a car: Simple ES only knows your position. Holt’s also knows your speed!
The formulas (simplified for intuition):
Level Equation: \[L_t = \alpha \times Y_t + (1-\alpha) \times (L_{t-1} + b_{t-1})\]
Trend Equation: \[b_t = \beta \times (L_t - L_{t-1}) + (1-\beta) \times b_{t-1}\]
Forecast Equation: \[\hat{Y}_{t+h} = L_t + h \times b_t\]
In plain English
Not too complicated, right?
Let’s walk through 6 periods manually to build intuition
# Sample data with clear upward trend
sales_data = np.array([100, 105, 112, 118, 124, 130])
# Parameters
alpha = 0.3 # Level smoothing
beta = 0.2 # Trend smoothing
# Initialize
level = sales_data[0] # Start at first observation
trend = sales_data[1] - sales_data[0] # Initial trend estimate
print(f"Period 1: Level={level:.1f}, Trend={trend:.1f}")
# Store level and trend history for visualization
level_history = [level]
trend_history = [trend]Period 1: Level=100.0, Trend=5.0
# Apply Holt's method for periods 2-6
for t in range(1, len(sales_data)):
# Update level
prev_level = level
level = alpha * sales_data[t] + (1 - alpha) * (prev_level + trend)
# Update trend
trend = beta * (level - prev_level) + (1 - beta) * trend
# Store for visualization
level_history.append(level)
trend_history.append(trend)
print(f"Period {t+1}: Sales={sales_data[t]}, Level={level:.1f}, Trend={trend:.1f}")Period 2: Sales=105, Level=105.0, Trend=5.0
Period 3: Sales=112, Level=110.6, Trend=5.1
Period 4: Sales=118, Level=116.4, Trend=5.3
Period 5: Sales=124, Level=122.4, Trend=5.4
Period 6: Sales=130, Level=128.4, Trend=5.5
Forecasts:
Period 7: 134.0 units
Period 8: 139.5 units
Period 9: 145.0 units

How do you pick the right smoothing parameters?
Alpha (Level Smoothing)
Beta (Trend Smoothing)
Best Practice: Let the algorithm optimize parameters automatically!
You can implement Holt’s method using Python’s statsmodels library!
Question: When should you use Holt’s method?
Question: When should you use NOT Holt’s method?
What if your data has BOTH trend AND seasonality?

Track THREE things separately: Level, Trend, AND Seasonality

How does seasonality combine with the level?
Additive Model \[Y_t = L_t + b_t + s_t\]
Multiplicative Model \[Y_t = L_t \times b_t \times s_t\]
The formulas (don’t panic - Python does this for you!)
Additive Model:
\[L_t = \alpha(Y_t - s_{t-m}) + (1-\alpha)(L_{t-1} + b_{t-1})\] \[b_t = \beta(L_t - L_{t-1}) + (1-\beta)b_{t-1}\] \[s_t = \gamma(Y_t - L_t) + (1-\gamma)s_{t-m}\] \[\hat{Y}_{t+h} = L_t + hb_t + s_{t+h-m}\]
In plain English
Parameters:
\(\alpha\) (level), \(\beta\) (trend), \(\gamma\) (seasonal), m (seasonal period length)
Understanding seasonal patterns with quarterly sales
Quarterly Sales Pattern:
How Holt-Winters Works
Q4 is typically 35% higher than Q1 in retail! Holt-Winters captures this automatically.

Notice how the forecast continues the seasonal pattern while following the trend!
Question: When should you use Holt-Winters method?
Question: When should you AVOID Holt-Winters method?
How wrong were we?
Mean Absolute Error (MAE): Average size of mistakes \[\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |Actual_i - Forecast_i|\]
Root Mean Squared Error (RMSE): Penalizes large errors more \[\text{RMSE} = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (Actual_i - Forecast_i)^2}\]
Easy with Python
# Example: Compare two forecasting methods
actual = np.array([100, 105, 110, 108, 112])
forecast_a = np.array([98, 107, 109, 110, 111])
forecast_b = np.array([102, 103, 112, 106, 113])
mae_a = np.mean(np.abs(actual - forecast_a))
mae_b = np.mean(np.abs(actual - forecast_b))
print(f"Method A - MAE: {mae_a:.2f} units")
print(f"Method B - MAE: {mae_b:.2f} units")
print(f"\nBetter method: {'A' if mae_a < mae_b else 'B'}")Method A - MAE: 1.60 units
Method B - MAE: 1.80 units
Better method: A

Start simple: Try moving average first as baseline, then add complexity only if needed!
Not all forecast errors are equal!
Example: Winter Coats
Question: What is your intuition here?
Sometimes it’s cheaper to overstock than to miss sales!
Underforecast by 100 units:
Overforecast by 100 units:
The “best” forecast depends on your business context.
All the hands-on coding happens in the interactive tutorial!
The notebook guides you step-by-step through Bean Counter’s seasonal demand forecasting challenge!
Can machines predict better than classical methods?
What AI/ML brings to forecasting:
AI doesn’t replace human judgment, it augments it when you have enough data!
Overview of popular techniques
Traditional ML:
Deep Learning:
More complex ≠ Better! Simple methods often win in forecasting.
Question: What happens when we train an AI on all our data and use it to predict… the same data?

Never judge a complex model on the data it learned from!

When future information sneaks into your training data
Data leakage can make a terrible model look amazing… until it fails in production!

Unlike regular cross-validation, we NEVER use future data to predict the past!
Use AI when you have:
Examples:
Don’t use AI when you have:
Examples:
How far into the future can we predict?

A forecast without confidence intervals is incomplete!

Why choose one method when you can combine several?
# Example: Combining multiple forecasts
ma_forecast = 120 # Moving average prediction
exp_forecast = 125 # Exponential smoothing prediction
seasonal_forecast = 135 # Seasonal model prediction
# Simple average (equal weights)
simple_combo = (ma_forecast + exp_forecast + seasonal_forecast) / 3
print(f"Simple combination: {simple_combo:.0f} units")
# Weighted average (based on historical accuracy)
weights = [0.3, 0.5, 0.2] # Exp smoothing was most accurate historically
weighted_combo = (ma_forecast * weights[0] +
exp_forecast * weights[1] +
seasonal_forecast * weights[2])
print(f"Weighted combination: {weighted_combo:.0f} units")Simple combination: 127 units
Weighted combination: 126 units

Long lead times = Forecasting further out = Less accuracy = More safety stock!
How much buffer do you need?
# Safety stock formula
import scipy.stats as stats
avg_weekly_demand = 300; std_weekly_demand = 40; lead_time_weeks = 3
service_level = 0.95 # Want 95% availability
# Z-score for 95% service level
z_score = stats.norm.ppf(service_level)
# Safety stock calculation
safety_stock = z_score * std_weekly_demand * np.sqrt(lead_time_weeks)
reorder_point = (avg_weekly_demand * lead_time_weeks) + safety_stock
print(f"Average demand during lead time: {avg_weekly_demand * lead_time_weeks} units")
print(f"Safety stock needed: {safety_stock:.0f} units")
print(f"Reorder point: {reorder_point:.0f} units")Average demand during lead time: 900 units
Safety stock needed: 114 units
Reorder point: 1014 units
Hour 2: This Lecture
Hour 3: Notebook
Hour 4: Competition
“The Christmas Predictor”
The Rules of Forecasting
Forecasting is both art and science
The Science:
The Art:
Make better decisions, not perfect predictions!
Take 20 minutes, then we start the practice notebook
Next up: You’ll become Bean Counter’s forecasting expert, preparing for seasonal demand!
Then: The MegaMart Christmas Challenge!
Forecasting the Future | Dr. Tobias Vlćek | Home