01
Flagging demand the drivers do not explain
Rolling Bayesian linear regression, Normal-Inverse-Gamma prior, posterior predictive p-values
- A fixed threshold, like mean plus or minus three standard deviations, does not move with the drivers, so it flags every promotion week. This model sets the expectation from the drivers. Say a promotion week should bring 120 units, give or take 10. If 160 arrive, only the gap the drivers do not explain is flagged.
- Demand = drivers (promotion, price, seasonality, weather) · weights + Gaussian noise. A zero-centred Gaussian prior on the weights (ridge regression in Bayesian form) plus an inverse-gamma prior on the noise variance is the Normal-Inverse-Gamma prior. It is conjugate, so each rolling-window fit gives the posterior and the posterior predictive, a Student-t, in closed form with no sampling. A two-sided posterior predictive p-value flags drops and spikes.
- I chose Bayesian regression because its flag comes with a reason. ARIMA, Isolation Forest and deep models can all flag a point, but ARIMA ignores the external drivers and the other two do not say why. Here the posterior weights carry credible intervals, so weight times driver value at the flagged point shows what moved demand. Driver attribution builds on this model.
deployed as a serviceon GCP Cloud Run, in Avathon's demand planning platform
Python, Normal-Inverse-Gamma updating, scikit-learn BayesianRidge, PyMC, FastAPI, Docker, GCP Cloud Run







