Skip to main content

A package for forecasting reconciliation.

Project description

pyhts

A python package for hierarchical forecasting, inspired by the hts package in R.

Features

  • Support pupular forecast reconciliation models in the literature, e.g. ols, wls, mint et al. Forecasting with temporal hierarchies will be supported in the future.
  • Multiple methods for the construction of hierarchy.
  • Use different base forecasters for different hierarchical levels.
  • Sklearn-like API.

Quick Demo

  • Load the Australia tourism flows data.
from pyhts._dataset import load_tourism

tourism_data = load_tourism()
train = tourism_data.iloc[:-12, :]
test = tourism_data.iloc[-12:, :]
  • Define the hierarchy.
from pyhts._hierarchy import Hierarchy

hierarchy = Hierarchy.from_names(tourism_data.columns, chars=[1, 1, 1])
print(hierarchy.node_name)
  • Create an ols forecasting reconciliation model with sklearn-like API.
from pyhts._HFModel import HFModel

model = HFModel(hierarchy=hierarchy, base_forecasters="arima",
                hf_method="comb", comb_method="ols")
  • Fit the model and produce forecasts.
model.fit(train)
forecasts = model.predict(horizon=12)
  • model.fit() fits the baseforecasters and computes the weighting matrix used to reconcile the base forecasts.

  • model.forecast() calculates the base forecasts for all levels and reconciles the base forecasts.

  • Obtain coherent forecasts of all the hierarchical levels.
all_level_forecasts = hierarchy.aggregate_ts(forecasts)
  • Evaluate the forecasting accuracy.
# accuracy of reconciled forecasts
hierarchy.accuracy(test, forecasts, hist=train, measure=['mase', 'rmse'])

# accuracy of base forecasts
base_forecasts = model.generate_base_forecast(horizon=12)
hierarchy.accuracy_base(test, base_forecasts, hist=train, measure=['mase', 'rmse'])

Because of the incoherence of base forecasts, base_forecasts are forecasts of all time series in the hierarchy, while coherent forecasts are forecasts of the bottom-level time series.

Documentation

See documentation here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhts-0.1.4.tar.gz (118.0 kB view details)

Uploaded Source

Built Distribution

pyhts-0.1.4-py3-none-any.whl (131.0 kB view details)

Uploaded Python 3

File details

Details for the file pyhts-0.1.4.tar.gz.

File metadata

  • Download URL: pyhts-0.1.4.tar.gz
  • Upload date:
  • Size: 118.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyhts-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ad820f12f355408a2097945c29e0db469d1163aef156232f75e7adecc329ad52
MD5 e283e88fc312f658105d9ea060622a68
BLAKE2b-256 27256df98948c1f9f312091764c9731cfa5dc7d2bf79c3b24aeed1e4741e6ad9

See more details on using hashes here.

File details

Details for the file pyhts-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pyhts-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 131.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyhts-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8bae1ecfd5cb1b610b631ea1f39164bae9849388a071aa5337d6e4a77005eb33
MD5 39192b689ad20a97849ce1645ff2b714
BLAKE2b-256 1f285b9e04684f3f3d870690ecec9a1018c709f5898001cad503b9c87f5e5d12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page