Temporal Fusion Transformer: Improving Retail Forecasting at Minimal Cost

Dmitry Polyakov27 Dec 2024

Problem

The ad-hoc analytics team at X5 Tech needed forecasts of retail turnover (RTO) and traffic (number of receipts) for Pyaterochka and Perekrestok stores. A production model already produced them, but they did not fit the team's task as they were. Resources were limited and deadlines tight, so building a new forecasting system was out of the question. The team needed a cheap way to reuse the existing forecasts and features and still gain accuracy.

Example from the article: one model per chain predicts RTO and traffic of every store 40 days ahead from 100 days of history, store attributes, calendar and the existing forecasts.

Solution in brief

Train one Temporal Fusion Transformer (TFT) per chain in Darts, with RTO and traffic as a two-component target. Inputs are the features the current system already uses plus its forecasts as future covariates; the forecast history is generated from the forecast error. A six-month weekly production test improved MAPE and WAPE by about 7% on average.

Questions this case answers
  • How to improve the accuracy of an existing forecasting system for many related series by training a second model on the same features plus the first model's forecasts
  • How to use another model's overlapping and improving forecasts as covariates when their historical errors differ from the future ones
  • How to improve retail store turnover and traffic forecasts when the existing model's forecasts cannot be used as they are?
  • How to forecast several related targets for many stores with one model?

Tools and methods

  • Temporal Fusion Transformer — multi-horizon, multi-target forecaster that handles static, past and future covariates
  • Quantile regression — loss that gives forecast intervals instead of one number
  • Darts — time series objects, scalers, TFT model, TFTExplainer
  • PyTorch Lightning, TensorBoard — training, early stopping, logging
  • scikit-learn — StandardScaler, MinMaxScaler, OrdinalEncoder
  • Backtesting — validation before the live run
Continue reading — it's free

Google or a one-time email code. No password.