Forecasting? Think Bayesian.
Imagine you are a store manager of a newly remodeled store in a buzzing, burgeoning neighborhood. A team used the best time series forecasting algorithm and predicted the growth of your store over the next few weeks. The grand opening ensured successful completion of sales targets in the first week, however, subsequent weeks upset your position, and gradually you fail to hit your numbers. As a result — your boss is on your back, customers are angry because the checkout counters are unmanned, while associates are complaining about low utilization. Turns out you have also used the forecasts to plan for the workforce in the store.
This obviously hypothetical, ominous situation may have occurred due to one of two things — a competitor in the vicinity that propped up while your store was renovating or the inability of the algorithm to prophesize the sales for a longer duration. We all can agree that the chances of the latter are much higher than the former.
It is well known amongst data scientists that non-stationary series, shortage of data points and inability to distinguish trends of a time series will lead to inaccurate forecasts. Ironically, these are also the drawbacks of many popular forecast algorithms. This compounded with the inability to validate time series makes elimination of error while forecasting, a critical problem for any retailer. Inaccurate forecasts inadvertently lead to over-staffing, over-stocking, or bad customer experience, thus resulting in loss of millions of dollars.
Knight in Shining Armor — BSTS
To overcome such challenges, one should turn to the revered Mr. Bayes and Steven L. Scott. We are all aware of the remarkable power Bayesian statistics possess to reduce uncertainty.
Scott was able to eliminate the complexities of a typical Bayesian algorithm and leverage its power to create Bayesian Structural Time Series (BSTS), which is able to cope with the unpredictability of data.
Structural Time Series models emulate and combine the indigenous features of regression models, ARMA, and exponential smoothening models.
BSTS — your friend or foe?
While BSTS has many advantages over traditional methods, it doesn’t guarantee the highest accuracy at all times.
More about BSTS…
Bayesian Structural Time Series model is also known as ‘state space models’ and ‘dynamic linear models’ is a class of time series model which can fit the structural change in time series dynamically. BSTS is the implementation of this model in R which is easy to use a function which requires a minimal mathematical understanding of the state space models.
BSTS model consists of two set of equations,
- Observational equation: Response variable as a function of predictors and/or latent variables
- State equations: How the parameters evolve over the time
BSTS also uses MCMC (Monte Carlo Markov Chain) to estimate, and broadly follows these steps:
- Prior distribution of parameters based on user inputs and state equations
- Fitted value of the response variables based on prior distribution in (1)
- Posterior distribution of parameters based on the error in step (2)
The above three steps constitute the Kalman filter. Apart from this, BSTS’s has an important feature: Spike and Slab. Using this method the regressors are tested randomly based on prior probabilities, and important regressors are retained
In essence, if you are looking for a versatile, easy to use Bayesian algorithm for forecasting, BSTS is your guy. Granted traditional algorithms did outperform BSTS for certain cases, however, overall this Bayesian algorithm has proved to be far superior to any of its contemporaries.
Do share your forecasting stories — what challenges have you encountered? How have you solved them? What opportunities for further improvement do you see?
You can refer to more details about BSTS by Steven L. Scott on:
- Math behind BSTS
- Bayesian Variable Selection for Now-casting Economic Time Series
- Predicting the Present with Bayesian Structural Time Series
- Sorry ARIMA, but I’m Going Bayesian
- BSTS cran page
PS: Want to thank my teammates — Nikesh Kumar Srivastava, Harsha, Mallik, Ojas, and Sameer for collaborating on this article with me.