TL;DR
This paper introduces a sparse hierarchical loss (HL) function that enables the training of coherent forecasting models for millions of products simultaneously. By integrating the hierarchical structure directly into the model's objective function and leveraging sparse linear algebra, the authors achieve up to a 10% improvement in accuracy while significantly reducing the computational overhead compared to traditional post-processing methods.
What Problem Does This Paper Address?
In large-scale e-commerce, forecasting isn't just about predicting how many units of a specific SKU will sell. Businesses also need "coherent" forecasts at higher levels—such as product categories, departments, or geographic regions—for logistics and financial planning. "Coherence" means the sum of individual product forecasts must exactly match the aggregate category forecast.
The traditional way to handle this is through reconciliation, a post-processing step that adjusts base forecasts to fit the hierarchy. However, standard reconciliation methods involve matrix inversions that scale cubically ($O(n^3)$) with the number of items. When you have millions of products, this becomes a massive computational bottleneck. Existing neural network approaches often struggle to scale to this magnitude or only handle temporal (time-based) hierarchies rather than cross-sectional (product-based) ones.
Methods
The authors propose a Sparse Hierarchical Loss (HL) function. Instead of forecasting every level of the hierarchy separately and then "fixing" them later, they train a single model to produce bottom-level (individual product) forecasts.
Key technical highlights include:
- End-to-End Training: The hierarchy is baked into the loss function itself. The model is penalized not just for errors at the product level, but also for errors in the implied aggregates.
- Sparse Linear Algebra: By implementing the loss function using sparse matrices (via SciPy), the authors reduce the computational complexity from cubic to quadratic ($O(n^2 \cdot l)$), where $l$ is the number of levels in the hierarchy. This makes it feasible to train on millions of items.
- Gradient Smoothing: Mathematically, the authors show that their hierarchical loss acts as a "smoothed" version of the standard squared error. It effectively distributes error information from aggregate levels back down to the individual products during training.
- Model Agnostic: While they demonstrate the method using LightGBM (a popular gradient-boosting framework), the loss function can theoretically be applied to any gradient-based learning system.
Datasets
The researchers evaluated their approach on two primary datasets:
- M5 Dataset: A public dataset from the 2020 M5 Forecasting Competition containing Walmart sales data for 3,049 products across 10 stores, organized into 12 cross-sectional aggregation levels.
- Proprietary bol Dataset: Data from bol, a major European e-commerce platform. This dataset is massive, featuring approximately 5 million unique items across 4 hierarchical levels, providing a true test of the method's scalability.
Key Insights and Ideas
- The "Bottom-Up" Advantage: The authors found that a single global model trained on bottom-level data consistently outperformed "separate aggregation" strategies (training different models for different levels).
- Efficiency in Prediction: Because the model learns to be coherent during training, there is no need for a complex reconciliation step during the inference/prediction phase. This simplifies deployment and reduces latency in production environments.
- Scaling is the Bottleneck: The paper emphasizes that for industrial applications, $O(n^3)$ is a non-starter. Their sparse implementation is what allows hierarchical forecasting to move from academic toy problems to real-world e-commerce catalogs.
- Hierarchy Sensitivity: Through "random hierarchy" experiments, they discovered that misspecifying the hierarchy (using a fake structure) degrades performance, proving that the model is genuinely learning from the real-world relationships between products.
Key Results
- Accuracy Gains: On the M5 dataset, the sparse HL function improved RMSE and MAE by up to 10% compared to baseline loss functions.
- Real-World Impact: At bol, the method resulted in a 2% improvement in RMSE and a 10% improvement in MAE at the product level compared to their existing production system.
- Computational Speedup: The sparse implementation was 3x faster to train than a dense version and orders of magnitude faster than traditional reconciliation methods at scale.
- Superiority over Statistical Baselines: The LightGBM model with HL outperformed traditional statistical methods like ARIMA and ETS by over 50% in terms of RMSE on the M5 data.
Limitations and Future Work
- Point Forecasts Only: The current work focuses on point forecasting (predicting a single number). The authors acknowledge that extending this to probabilistic forecasting (predicting a range or distribution) is a necessary next step.
- Temporal vs. Cross-sectional: While the math supports combining both temporal (daily/weekly/monthly) and cross-sectional (product/category) hierarchies, their experiments didn't show a clear accuracy benefit from doing both simultaneously yet. They suggest further research into how to balance these two types of structures.
- Hierarchy Knowledge: The method assumes the hierarchy is known and fixed. Future work could explore learning the hierarchy structure itself from the data.
Summary updated