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 import load_tourism

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

hierarchy = Hierarchy.new(tourism_data, [('state', 'region', 'city')])
print(hierarchy.node_name)
  • Create an ols forecasting reconciliation model with sklearn-like API.
from pyhts import HFModel

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

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

  • Obtain coherent forecasts of all the hierarchical levels.
all_level_ols = hierarchy.aggregate_ts(ols)
  • fit other methods using fitted base forecasters
model_wlss = HFModel(hierarchy, base_forecasters=model_ols.base_forecasters,
                     hf_method="comb", comb_method="wls", weights="structural")
model_wlss.fit(train)
wlss = model_wlss.predict(horizon=12)

model_wlsv = HFModel(hierarchy, base_forecasters=model_ols.base_forecasters,
                     hf_method="comb", comb_method="mint", weights="variance")
model_wlsv.fit(train)
wlsv = model_wlsv.predict(horizon=12)

model_shrink = HFModel(hierarchy, base_forecasters=model_ols.base_forecasters,
                       hf_method="comb", comb_method="mint", weights="shrinkage")
model_shrink.fit(train)
shrink = model_shrink.predict(horizon=12)
  • Evaluate the forecasting accuracy.
# accuracy of reconciled forecasts
accuracy = [hierarchy.accuracy(test, fcast, hist=train, measure=['mase', 'rmse'])
            for fcast in (ols, wlss, wlsv, shrink)]

# accuracy of base forecasts
base_forecasts = model_ols.generate_base_forecast(horizon=12)
accuracy_base = 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.2.0.tar.gz (116.9 kB view details)

Uploaded Source

Built Distribution

pyhts-0.2.0-py3-none-any.whl (116.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyhts-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9109b8f0a7751f52a57f80a217bcb8ee89b3ce95acdc1c17ccbf95c6e15c1b2
MD5 8cec1d1623d73d3b1cf4f91a8808a2cd
BLAKE2b-256 e1ea4f62bbebe907b85ace432695c0431281add46270e90a2555794eb15fab5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyhts-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 116.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c8e0ab1ecae33d9bf3dae428d99421af88b96b54c9544318b6e7b841d1f6bfb
MD5 f375059fa95986f1c247e067cbf2e761
BLAKE2b-256 d65c49ec6598734642a57416b5da8d8bc032c8317fbaf2f7ec494458c97a5ae6

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