Skip to main content

A library that unifies the API for most commonly used libraries and modelling techniques for time-series forecasting in the Python ecosystem.

Project description

CI CD Documentation Status PyPI Version Conda Version Code Coverage Binder License Contributors Code style: black

HCrystal Ball


A library that unifies the API for most commonly
used libraries and modelling techniques for time-series
forecasting in the Python ecosystem.



HCrystal Ball consists of two main parts:

  • Wrappers - which bring different 3rd party libraries to time series compatible sklearn API
  • Model Selection - to enable gridsearch over wrappers, general or custom made transformers and add convenient layer over whole process (access to results, plots, storage, ...)

Documentation

See examples, tutorials, contribution, API and more on the documentation site try notebooks on binder or browse example notebooks in docs/examples directly.

Core Installation

If you want really minimal installation, you can install from pip or from conda-forge

pip install hcrystalball
conda install -c conda-forge hcrystalball

Typical Installation

Very often you will want to use more wrappers, than just Sklearn, run examples in jupyterlab, or execute model selection in parallel. Getting such dependencies to play together nicely might be cumbersome, so checking envrionment.yml might give you faster start.

# get dependencies file, e.g. using curl
curl -O https://raw.githubusercontent.com/heidelbergcement/hcrystalball/master/environment.yml
# check comments in environment.yml, keep or remove as requested, than create environment using
conda env create -f environment.yml
# activate the environment
conda activate hcrystalball
# if you want to see progress bar in jupyterlab, execute also
jupyter labextension install @jupyter-widgets/jupyterlab-manager
# install the library from pip
pip install hcrystalball
# or from conda
conda install -c conda-forge hcrystalball

Development Installation:

To have everything in place including docs build or executing tests, execute following code

git clone https://github.com/heidelbergcement/hcrystalball
cd hcrystalball
conda env create -f environment.yml
conda activate hcrystalball
# ensures interactive progress bar will work in example notebooks
jupyter labextension install @jupyter-widgets/jupyterlab-manager
python setup.py develop

Example Usage

Wrappers

from hcrystalball.utils import generate_tsdata
from hcrystalball.wrappers import ProphetWrapper

X, y = generate_tsdata(n_dates=365*2)
X_train, y_train, X_test, y_test = X[:-10], y[:-10], X[-10:], y[-10:]

model = ProphetWrapper()
y_pred = model.fit(X_train, y_train).predict(X_test)
y_pred
            prophet
2018-12-22  6.066999
2018-12-23  6.050076
2018-12-24  6.105620
2018-12-25  6.141953
2018-12-26  6.150229
2018-12-27  6.163615
2018-12-28  6.147420
2018-12-29  6.048633
2018-12-30  6.031711
2018-12-31  6.087255

Model Selection

import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('seaborn')
plt.rcParams['figure.figsize'] = [12, 6]

from hcrystalball.utils import get_sales_data
from hcrystalball.model_selection import ModelSelector

df = get_sales_data(n_dates=200,
                    n_assortments=1,
                    n_states=2,
                    n_stores=2)

ms = ModelSelector(horizon=10,
                   frequency="D",
                   country_code_column="HolidayCode",
                   )

ms.create_gridsearch(n_splits=2,
                     sklearn_models=True,
                     prophet_models=False,
                     exog_cols=["Open","Promo","SchoolHoliday","Promo2"],
                     )

ms.select_model(df=df,
                target_col_name="Sales",
                partition_columns=["Assortment", "State","Store"],
                )

ms.plot_results(plot_from="2015-06-01",
                partitions=[{"Assortment":"a","State":"NW","Store":335}]
               )

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

hcrystalball-0.1.12.tar.gz (8.3 MB view details)

Uploaded Source

Built Distribution

hcrystalball-0.1.12-py2.py3-none-any.whl (788.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file hcrystalball-0.1.12.tar.gz.

File metadata

  • Download URL: hcrystalball-0.1.12.tar.gz
  • Upload date:
  • Size: 8.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

File hashes

Hashes for hcrystalball-0.1.12.tar.gz
Algorithm Hash digest
SHA256 1b5a1fdbdc105cf0adc8fba9444ae768610ddee99c3b3bbf48f8f0bcaeabf41c
MD5 9ab2fcf9dec7b89c8a86f824e00d5afc
BLAKE2b-256 c4d8d4ac5b406a2ce1d40bc605d3b6d7d86d3571bc721c50ea1eb4fad5d6a68a

See more details on using hashes here.

File details

Details for the file hcrystalball-0.1.12-py2.py3-none-any.whl.

File metadata

  • Download URL: hcrystalball-0.1.12-py2.py3-none-any.whl
  • Upload date:
  • Size: 788.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

File hashes

Hashes for hcrystalball-0.1.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3f42c0e962b6c0fe972c8afa51cfb04be8ede91d3e3de0b3a591318b8f25d6e6
MD5 4df2b15d5441a138ae23a0211ecb9694
BLAKE2b-256 9125916c061d067b0200acffa1efa2dd9e7114813012d40d8af66fad7f7e44eb

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