Capstone 2 of 8
Store demand forecasting
Business requirement
A retail chain wants next-14-day demand per product per store so it orders enough stock without filling the warehouse.
Lessons to finish first
Architecture
- Synthetic daily sales with trend, weekly pattern and promotions
- Time-based train/validation split
- Naive and seasonal-naive baselines
- Feature model (lags, day of week, promotions)
- Backtest over several windows
- Forecast file and error report
Build steps
- Generate two years of daily sales for 10 products in 3 stores, with weekly seasonality, holidays and promotions.
- Plot one series and describe trend, seasonality and noise in words.
- Split by time: train on the past, validate on the most recent weeks (never shuffle).
- Build two baselines: yesterday’s value and the same day last week.
- Train a gradient-boosting model on lag features, rolling means, day of week and promotion flags.
- Backtest over at least four rolling windows; report MAE and the share of days under-forecast.
- Produce a 14-day forecast with a simple uncertainty band (for example from backtest errors).
Python route and .NET route
- Python
- pandas (date features, shift, rolling), scikit-learn HistGradientBoostingRegressor, matplotlib for plots. The time-series demo in the examples folder is the starting point.
- .NET (C#)
- ML.NET Microsoft.ML.TimeSeries (ForecastBySsa) for single series, or FastTree regression on lag features for many series; write results with CsvHelper or plain File APIs.
Example input and output
- Input
store S2, product P7, history to 2026-10-31- Output
14 rows: date, forecast, low, high
Data
Synthetic daily sales generated with a script (known seasonality so you can check the model finds it).
Starter file structure
forecast/
data/generate.py
features.py
backtest.py | Backtest/Program.cs
forecast.py
README.mdTests
- No future data in any feature (lags only use past days)
- Model beats seasonal-naive on backtest MAE
- Forecast file has exactly 14 future dates per series
How it will be judged
- Time-based validation used correctly
- Errors reported per product and overall
- Business reading of the error (stock-outs versus overstock)
Security and privacy
Sales data is commercially sensitive: keep it out of public repositories and logs.
Definition of done
- Backtest table with baselines and model
- A 14-day forecast with bands for every series
- Written note on where the model fails
Stretch goals
- Forecast at weekly level and compare
- Add weather or holiday features
- Retrain automatically when error rises
What to show an employer
Backtest chart for one product with actual versus forecast and the baseline.
Completion
Saved in this browser only.