Hierarchical Methods Time series forecasting
Project description
Nixtla
Hierarchical 👑 Forecast
Hierarchical forecasting with statistical and econometric methods
HierarchicalForecast offers a collection of reconciliation methods, including BottomUp
, TopDown
, MiddleOut
, MinTrace
and ERM
. And Probabilistic coherent predictions including Normality
, Bootstrap
, and PERMBU
.
🎊 Features
- Classic reconciliation methods:
BottomUp
: Simple addition to the upper levels.TopDown
: Distributes the top levels forecasts trough the hierarchies.
- Alternative reconciliation methods:
MiddleOut
: It anchors the base predictions in a middle level. The levels above the base predictions use the bottom-up approach, while the levels below use a top-down.MinTrace
: Minimizes the total forecast variance of the space of coherent forecasts, with the Minimum Trace reconciliation.ERM
: Optimizes the reconciliation matrix minimizing an L1 regularized objective.
- Probabilistic coherent methods:
Normality
: Uses MinTrace variance-covariance closed form matrix under a normality assumption.Bootstrap
: Generates distribution of hierarchically reconciled predictions using Gamakumara's bootstrap approach.PERMBU
: Reconciles independent sample predictions by reinjecting multivariate dependence with estimated rank permutation copulas, and performing a Bottom-Up aggregation.
Missing something? Please open an issue here or write us in
📖 Why?
Short: We want to contribute to the ML field by providing reliable baselines and benchmarks for hierarchical forecasting task in industry and academia. Here's the complete paper.
Verbose: HierarchicalForecast
integrates publicly available processed datasets, evaluation metrics, and a curated set of standard statistical baselines. In this library we provide usage examples and references to extensive experiments where we showcase the baseline's use and evaluate the accuracy of their predictions. With this work, we hope to contribute to Machine Learning forecasting by bridging the gap to statistical and econometric modeling, as well as providing tools for the development of novel hierarchical forecasting algorithms rooted in a thorough comparison of these well-established models. We intend to continue maintaining and increasing the repository, promoting collaboration across the forecasting community.
💻 Installation
PyPI
You can install HierarchicalForecast
's released version from the Python package index pip with:
pip install hierarchicalforecast
(Installing inside a python virtualenvironment or a conda environment is recommended.)
Conda
Also you can install HierarchicalForecast
's released version from conda with:
conda install -c conda-forge hierarchicalforecast
(Installing inside a python virtualenvironment or a conda environment is recommended.)
Dev Mode
If you want to make some modifications to the code and see the effects in real time (without reinstalling), follow the steps below:
git clone https://github.com/Nixtla/hierarchicalforecast.git
cd hierarchicalforecast
pip install -e .
🧬 How to use
The following example needs statsforecast
and datasetsforecast
as additional packages. If not installed, install it via your preferred method, e.g. pip install statsforecast datasetsforecast
.
The datasetsforecast
library allows us to download hierarhical datasets and we will use statsforecast
to compute base forecasts to be reconciled.
You can open this example in Colab
import numpy as np
import pandas as pd
#obtain hierarchical dataset
from datasetsforecast.hierarchical import HierarchicalData
# compute base forecast no coherent
from statsforecast.core import StatsForecast
from statsforecast.models import AutoARIMA, Naive
#obtain hierarchical reconciliation methods and evaluation
from hierarchicalforecast.core import HierarchicalReconciliation
from hierarchicalforecast.evaluation import HierarchicalEvaluation
from hierarchicalforecast.methods import BottomUp, TopDown, MiddleOut
# Load TourismSmall dataset
Y_df, S, tags = HierarchicalData.load('./data', 'TourismSmall')
Y_df['ds'] = pd.to_datetime(Y_df['ds'])
#split train/test sets
Y_test_df = Y_df.groupby('unique_id').tail(12)
Y_train_df = Y_df.drop(Y_test_df.index)
Y_test_df = Y_test_df.set_index('unique_id')
Y_train_df = Y_train_df.set_index('unique_id')
# Compute base auto-ARIMA predictions
fcst = StatsForecast(df=Y_train_df,
models=[AutoARIMA(season_length=12), Naive()],
freq='M', n_jobs=-1)
Y_hat_df = fcst.forecast(h=12)
# Reconcile the base predictions
reconcilers = [
BottomUp(),
TopDown(method='forecast_proportions'),
MiddleOut(middle_level='Country/Purpose/State',
top_down_method='forecast_proportions')
]
hrec = HierarchicalReconciliation(reconcilers=reconcilers)
Y_rec_df = hrec.reconcile(Y_hat_df=Y_hat_df, Y_df=Y_train_df,
S=S, tags=tags)
Evaluation
def mse(y, y_hat):
return np.mean((y-y_hat)**2)
evaluator = HierarchicalEvaluation(evaluators=[mse])
evaluator.evaluate(Y_hat_df=Y_rec_df, Y_test=Y_test_df,
tags=tags, benchmark='Naive')
📖 Documentation (WIP)
Here is a link to the documentation.
📃 License
This project is licensed under the MIT License - see the LICENSE file for details.
🏟 HTS projects
In the R ecosystem, we recommend checking out fable, and the now-retired hts. In Python we want to acknowledge the following libraries hiere2e, sktime, darts, pyhts, scikit-hts.
📚 References and Acknowledgements
This work is highly influenced by the fantastic work of previous contributors and other scholars who previously proposed the reconciliation methods presented here. We want to highlight the work of Rob Hyndman, George Athanasopoulos, Shanika L. Wickramasuriya, Souhaib Ben Taieb, and Bonsoo Koo. For a full reference link, please visit the Reference section of this paper. We encourage users to explore this literature review.
🙏 How to cite
If you enjoy or benefit from using these Python implementations, a citation to this hierarchical forecasting reference paper will be greatly appreciated.
@article{olivares2022hierarchicalforecast,
author = {Kin G. Olivares and
Federico Garza and
David Luo and
Cristian Challú and
Max Mergenthaler and
Artur Dubrawski},
title = {HierarchicalForecast: A Reference Framework for Hierarchical Forecasting in Python},
journal = {Computing Research Repository},
volume = {abs/2207.03517},
year = {2022},
url = {https://arxiv.org/abs/2207.03517},
archivePrefix = {arXiv}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hierarchicalforecast-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ba628ed32418d752429f391e035e9928564e0e5d8b367eca68bb7d638c8a2d |
|
MD5 | 03bc61524ae07a3357f2f42d40cccecf |
|
BLAKE2b-256 | 7fd377cc01aaf887d579cbd3470eb5f7665827668772afc888a8134a491c1127 |
Hashes for hierarchicalforecast-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbaf925a3e80967da117a2f13a6c33f704b9bc2a46b204097152dd7ae35f0268 |
|
MD5 | f6d0d58733d040e63be46faba25af9f7 |
|
BLAKE2b-256 | ae4ad99090b2d13892a074f9dd2d59eb466088f9f6d00de24fb14f8f9012c882 |