Skip to main content

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.

Metadata

Release files for pyhts 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyhts 0.1.4
File Size Uploaded
pyhts-0.1.4.tar.gz 118.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyhts 0.1.4
File Interpreter ABI Platform
pyhts-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 249.0 kB

Release files / pyhts-0.1.4.tar.gz

Download URL pyhts-0.1.4.tar.gz
Size 118.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ad820f12f355408a2097945c29e0db469d1163aef156232f75e7adecc329ad52
BLAKE2b-256 checksum
How to use checksums
27256df98948c1f9f312091764c9731cfa5dc7d2bf79c3b24aeed1e4741e6ad9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / pyhts-0.1.4-py3-none-any.whl

Download URL pyhts-0.1.4-py3-none-any.whl
Size 131.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bae1ecfd5cb1b610b631ea1f39164bae9849388a071aa5337d6e4a77005eb33
BLAKE2b-256 checksum
How to use checksums
1f285b9e04684f3f3d870690ecec9a1018c709f5898001cad503b9c87f5e5d12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.5

2 release files

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page