Skip to main content

A package for forecasting reconciliation.

Project description

py-hts

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

features

  • support pupular forecast reconciliation models in the literature, e.g. ols, wls, mint et al. Temporal Hierarchy will be supported in the future.
  • multiple methods for the construction of hierarchy.
  • use different base forecasters for different hierarchical levels.
  • familiar sklearn-like API

Quick Demo

Load tourism data, which is tourism demand measured by the number of "visitor nights" in Australia.

from pyhts.dataset import load_tourism

tourism_data = load_tourism()
train = tourism_data.iloc[:-12, :]
test = tourism_data.iloc[-12:, :]

Define 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 forecast.

model.fit(train)
forecasts = model.predict(horizon=12)
  • model.fit() will fit the baseforecasters and compute the weighting matrix used to reconcile the base forecast.

  • model.forecast() will calculate base forecasts of all levels and reconcile the base forecasts.

Obtain coherent forecasts of all hierarchical levels.

all_level_forecasts = hierarchy.aggregate_ts(forecasts)

evaluate 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 bottom time series.

Documentation

see documentation here https://angelpone.github.io/pyhts/.

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.0.tar.gz (118.9 kB view details)

Uploaded Source

Built Distribution

pyhts-0.1.0-py3-none-any.whl (118.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyhts-0.1.0.tar.gz
  • Upload date:
  • Size: 118.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyhts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2845486ba8aa7e7e5d8eb9d4081ecb8e55064fc1b8e16d3690e4a63850b7e5b4
MD5 0dbf713c69e168970a666fc39771d69f
BLAKE2b-256 e6c856c17649396779b2e2306068ad8b07ad0cb449bb2b5bf2d77ab892cef185

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyhts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 118.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyhts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 881c9d2d7b226b1b1865e12be202fd3e6696d4ff5a1c64dad6ecd55f655747b4
MD5 1d3db13787354752da95448e810f5925
BLAKE2b-256 100ba56f7da744df5e58d2c4dba456f49d669b629a38e73cb973ea20d7e726a0

See more details on using hashes here.

Supported by

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