A Python package for Bayesian forecasting with object-oriented design and probabilistic models under the hood.

Orbit banner


GitHub release (latest SemVer) PyPI Build Status Documentation Status PyPI - Python Version Downloads

Disclaimer

This project

  • is stable and being incubated for long-term support. It may contain new experimental code, for which APIs are subject to change.
  • requires PyStan as a system dependency. PyStan is licensed under GPLv3, which is a free, copyleft license for software.

Orbit: A Python Package for Bayesian Forecasting

Orbit is a Python package for Bayesian time series forecasting and inference. It provides a familiar and intuitive initialize-fit-predict interface for time series tasks, while utilizing probabilistic programing languages under the hood.

Currently, it supports concrete implementations for the following models:

  • Exponential Smoothing (ETS)
  • Damped Local Trend (DLT)
  • Local Global Trend (LGT)

It also supports the following sampling methods for model estimation:

  • Markov-Chain Monte Carlo (MCMC) as a full sampling method
  • Maximum a Posteriori (MAP) as a point estimate method
  • Variational Inference (VI) as a hybrid-sampling method on approximate distribution

Installation

Installing Stable Release

Install from PyPi:

$ pip install orbit-ml

Install from source:

$ git clone https://github.com/uber/orbit.git
$ cd orbit
$ pip install -r requirements.txt
$ pip install .

Installing from Dev Branch

$ pip install git+https://github.com/uber/[email protected]

Quick Start with Damped-Local-Trend (DLT) Model

FULL Bayesian Prediction

from orbit.utils.dataset import load_iclaims
from orbit.models.dlt import DLTFull
from orbit.diagnostics.plot import plot_predicted_data

# log-transformed data
df = load_iclaims()
# train-test split
test_size=52
train_df=df[:-test_size]
test_df=df[-test_size:]

dlt = DLTFull(
    response_col='claims', date_col='week',
    regressor_col=['trend.unemploy', 'trend.filling', 'trend.job'],
    seasonality=52,
)
dlt.fit(df=train_df)

# outcomes data frame
predicted_df = dlt.predict(df=test_df)

plot_predicted_data(
    training_actual_df=train_df, predicted_df=predicted_df,
    date_col=dlt.date_col, actual_col=dlt.response_col,
    test_actual_df=test_df
)

full-pred

Contributing

We welcome community contributors to the project. Before you start, please read our code of conduct and check out contributing guidelines first.

Versioning

We document versions and changes in our changelog.

References

Documentation

Citation

To cite Orbit in publications, refer to the following whitepaper:

Orbit: Probabilistic Forecast with Exponential Smoothing

Bibtex:

@misc{
    ng2020orbit,
    title={Orbit: Probabilistic Forecast with Exponential Smoothing},
    author={Edwin Ng,
        Zhishi Wang,
        Huigang Chen,
        Steve Yang,
        Slawek Smyl},
    year={2020}, eprint={2004.08492}, archivePrefix={arXiv}, primaryClass={stat.CO}
}

Papers

  • Hyndman, R., Koehler, A. B., Ord, J. K., and Snyder, R. D. Forecasting with exponential smoothing: the state space approach. Springer Science & Business Media, 2008.
  • Bingham, E., Chen, J. P., Jankowiak, M., Obermeyer, F., Pradhan, N., Karaletsos, T., Singh, R., Szerlip, P., Horsfall, P., and Goodman, N. D. Pyro: Deep universal probabilistic programming. The Journal of Machine Learning Research, 20(1):973–978, 2019.
  • Taylor, S. J. and Letham, B. Forecasting at scale. The American Statistician, 72(1):37–45, 2018.
  • Hoffman, M.D. and Gelman, A. The No-U-Turn sampler: adaptively setting path lengths in Hamiltonian Monte Carlo. J. Mach. Learn. Res., 15(1), pp.1593-1623, 2014.

Related projects

Owner
Uber Open Source
Open Source Software at Uber
Uber Open Source
Comments
  • Quick Start Example executes infinitely

    Quick Start Example executes infinitely

    Describe the bug Trying to launch example from https://uber.github.io/orbit/tutorials/quick_start.html The line dlt.fit(df=train_df) is executed infinitely (I've been waiting for hours and nothing happened)

    To Reproduce Steps to reproduce the behavior: Code:

    %matplotlib inline
    import orbit
    from orbit.utils.dataset import load_iclaims
    from orbit.models.dlt import ETSFull
    from orbit.diagnostics.plot import plot_predicted_data
    
    df = load_iclaims()
    date_col = 'week'
    response_col = 'claims'
    test_size = 52
    train_df = df[:-test_size]
    test_df = df[-test_size:]
    
    dlt = ETSFull(
        response_col=response_col,
        date_col=date_col,
        seasonality=52,
        seed=8888,
    )
    
    dlt.fit(df=train_df)
    
    

    Expected behavior As in the example, I expected the code to compile in few minutes.

    Environment (please complete the following information):

    • OS: macOS Big Sur 11.4
    • Python Version: 3.8.5
    • Versions of Major Dependencies pandas==1.1.3, scikit-learn==0.23.1, cython==0.29.21 , orbit==1.0.15
  • Integrating LGT/DLT into ETS Base

    Integrating LGT/DLT into ETS Base

    Description

    A significant refactor of ETS related models. To make models more extensible, we want to create a base named as ETS to build core logic such as smoothing parameters and attributes, regression etc.

    Fixes # (issue)

    Type of change

    • [x] fully build ETS
    • [x] unit test
    • [x] doc update
    • [x] refactor LGT
    • [x] refactor DLT

    How Has This Been Tested?

    • [x] unit tests on ETS
    • [x] unit tests different position of columns of regressor matrices
    • [x] compare predictions of LGT and DLT against master
    • [x] unit tests for LGT/DLT negative regressors test cases
  • Changing Default Values of plotting and prediction percentiles

    Changing Default Values of plotting and prediction percentiles

    Description

    Having prediction percentiles=None is quite annoying since I find more often the reason to have LGT/DTLFull is to get reliable inference. Each time if I want to create a new DLTFULL(after testing DLTMAP), i need to figure out the right arg.

    Fixes # (issue)

    Change prediction_percentiles=None = prediction_percentiles=[5,95] and some default plotting value changed to make it less input required if we always use default prediction outcomes.

    Please delete options that are not relevant.

    • [x] Change related tutorial/docs update for cosmetic purpose (should not trigger any error)
    • [x] restore prediction outcomes label by using input prediction percentiles directly
    • [x] set prediction percentiles default as [5, 95] internally

    How Has This Been Tested?

    Since it is plotting, no test is related for this.

  • UnboundLocalError: local variable 'pool' referenced before assignment

    UnboundLocalError: local variable 'pool' referenced before assignment

    lgt = LGT( response_col="Sales", date_col="Date", estimator='stan-mcmc', seasonality=12, seed=8888 ) lgt.fit(df)

    When i using it in ipynb file i didn't get any error but when i am using in .py file i getting error as UnboundLocalError: local variable 'pool' referenced before assignment i try to change few things in _map_parallel function but it won't work can you help to achive mcmc

  • No such file or directory: '/usr/local/lib/python3.7/dist-packages/orbit/plot_style.mplstyle'

    No such file or directory: '/usr/local/lib/python3.7/dist-packages/orbit/plot_style.mplstyle'

    Describe the bug I'm trying to use the example in the quickstart guide. When I try to plot I get the following error, No such file or directory: '/usr/local/lib/python3.7/dist-packages/orbit/plot_style.mplstyle'

    To Reproduce quickstart guide

    Expected behavior Plotted data image

    Screenshots image

    Environment (please complete the following information): Colab

  • Update tutorials notebooks

    Update tutorials notebooks

    Description

    Please include a summary of the change and which issue is fixed.

    Fixes # 309

    1. Updated tutorials:
    • quick start for LGT and DLT
    • utilities for simulation data generation
    1. Add tox.int for linting
    2. Fix lint issues in code
    3. Add encoding type when compiling the stan file
  • More user friendly reminder of data gap

    More user friendly reminder of data gap

    Describe the bug Following error occures while fitting some KTR models: ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 4)

    Stacktrace:

        dlt_reg.fit(df=df, point_method='mean')
    File "/opt/conda/envs/lib/python3.7/site-packages/orbit/forecaster/svi.py", line 25, in fit
        super().fit(df)
    File "/opt/conda/envs/lib/python3.7/site-packages/orbit/forecaster/forecaster.py", line 128, in fit
        self._model.set_dynamic_attributes(df=df, training_meta=self.get_training_meta())
    File "/opt/conda/envs/lib/python3.7/site-packages/orbit/template/ktr.py", line 798, in set_dynamic_attributes
        self._set_levs_and_seas(df, training_meta)
    File "/opt/conda/envs/lib/python3.7/site-packages/orbit/template/ktr.py", line 768, in _set_levs_and_seas
        self._seasonality_fs_order)
    File "/opt/conda/envs/lib/python3.7/site-packages/orbit/template/ktr.py", line 682, in _generate_seas
        seas_coef = np.squeeze(np.matmul(coef_knot, coef_kernel.transpose(1, 0)), axis=0).transpose(1, 0)
    

    Environment (please complete the following information):

    • OS: Ubuntu
    • Python Version: 3.7
    • orbit-ml==1.1.0dev
  • added a few eda plotting functions

    added a few eda plotting functions

    eda 5 plotting functions

    Description

    Please include a summary of the change and which issue is fixed.

    1. time series heat map
    2. correlcation heatmap
    3. Year over year outcome vs event
    4. Dual axis time series ploot
    5. a wrap grid chart for quick glance of selected features

    Fixes # (issue)

    Type of change

    Please delete options that are not relevant.

    • [ ] New feature

    How Has This Been Tested?

    Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests. manual tests

  • Initialization failed

    Initialization failed

    Describe the bug When fitting the ETSFull and ETSMap models on an hourly time frame, I'm receiving the following error: Initialization failed. You can find the full error description below in the Additional context

    Expected behavior I want to forecasting the demand according to an hourly data frame ( or 30 mins time frame). This is not even starting by fitting.

    Screenshots If applicable, add screenshots to help explain your problem.

    Environment (please complete the following information):

    • OS: macOS
    • Python Version: Python 3.6. 9
    • Versions of Major Dependencies : pandas==1.1.5, scikit-learn==0.24.2, 'matplotlib==3.3.4'

    Additional context

    RemoteTraceback Traceback (most recent call last) RemoteTraceback: """ Traceback (most recent call last): File "/usr/lib/python3.7/multiprocessing/pool.py", line 121, in worker result = (True, func(*args, **kwds)) File "/usr/lib/python3.7/multiprocessing/pool.py", line 44, in mapstar return list(map(*args)) File "stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396.pyx", line 373, in stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396._call_sampler_star File "stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396.pyx", line 406, in stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396._call_sampler RuntimeError: Initialization failed. """

    The above exception was the direct cause of the following exception:

    RuntimeError Traceback (most recent call last) in () ----> 1 dlt.fit(train_df)

    7 frames /usr/lib/python3.7/multiprocessing/pool.py in mapstar() 42 43 def mapstar(args): ---> 44 return list(map(*args)) 45 46 def starmapstar(args):

    stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396.pyx in stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396._call_sampler_star()

    stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396.pyx in stanfit4anon_model_982090c5656030fa038b63e5c383dbff_326254919482697396._call_sampler()

    RuntimeError: Initialization failed.

  • Minor: Plot Components Warning

    Minor: Plot Components Warning

    Describe the bug I saw a warning when I run components plot in dev branch.

    To Reproduce

    plot_predicted_components(predicted_df=predicted_df, date_col=date_col, 
                            plot_components=['trend', 'seasonality_7', 'seasonality_365.25'])
    

    cell no. 11 under examples/ktrlie.ipynb

    Screenshots Screen Shot 2021-05-23 at 11 54 36 AM

    Environment (please complete the following information):

    • Python Version: 3.7
    • Matplotlib Version: 3.3.4
  • Simple Bayesian linear model

    Simple Bayesian linear model

    Description

    Implementation of simple Bayesian linear model. Currently in Stan only. (in Pyro in near future) The model is the most basic Bayesian linear regression with all default non-informative priors in regression coefficients and error.

    Fixes #423

    Type of change

    • [x] New feature
    • [ ] This change requires a documentation update

    How Has This Been Tested?

    A few unit tests are written, with respect to initialization, StanMCMC, StanMAP.

  • Refactor Estimator Classes

    Refactor Estimator Classes

    Right now we have the model load method separate between estimators and they are not implemented as a class function. It looks more readable to do so instead of (current approach) using a independent functions outside.

  • cmdstanpy instead of pystan

    cmdstanpy instead of pystan

    Hi! Is there any plan to move from pystan to cmdstanpy? The installation is sometimes hard because of, for example https://discourse.mc-stan.org/t/error-installing-pystan-in-python-3-10-with-gcc-9-2-0/27895/7

  • Report the exact missing regressor columns

    Report the exact missing regressor columns

    Right now, error message only indicate a miss match but not telling the exact missing column(s). We can report the missing columns explicitly in the condition of a missing check failure.

  • Error while running ets.fit : distutils.errors.DistutilsExecError: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1

    Error while running ets.fit : distutils.errors.DistutilsExecError: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1

    Describe the bug I am having issues running Pystan package. I have installed GCC compiler and also set path to C:\MinGW\bin\gcc.exe. I have also created disutils.cfg file as per the instructions on different forums. I am still unable to run Orbit ML code.

    Screenshots < INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_f7eb4ed4486a30ffc26b04f2ada67b48 NOW. Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\distutils\cygwinccompiler.py", line 173, in _compile extra_postargs) File "C:\ProgramData\Anaconda3\lib\distutils\ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "C:\ProgramData\Anaconda3\lib\distutils\spawn.py", line 38, in spawn _spawn_nt(cmd, search_path, dry_run=dry_run) File "C:\ProgramData\Anaconda3\lib\distutils\spawn.py", line 81, in _spawn_nt "command %r failed with exit status %d" % (cmd, rc)) distutils.errors.DistutilsExecError: command 'C:\MinGW\bin\gcc.exe' failed with exit status 1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "C:/ProgramData/Anaconda3/envs/Forecasting_Algorithms/orbit_ml.py", line 35, in ets.fit(df=train_df) File "C:\ProgramData\Anaconda3\envs\Temp\Forecasting_Algorithms\lib\site-packages\orbit\forecaster\full_bayes.py", line 29, in fit super().fit(df, sampling_temperature=sampling_temperature) File "C:\ProgramData\Anaconda3\envs\Temp\Forecasting_Algorithms\lib\site-packages\orbit\forecaster\forecaster.py", line 169, in fit **kwargs, File "C:\ProgramData\Anaconda3\envs\Temp\Forecasting_Algorithms\lib\site-packages\orbit\estimators\stan_estimator.py", line 118, in fit compiled_stan_file = get_compiled_stan_model(model_name) File "C:\ProgramData\Anaconda3\envs\Temp\Forecasting_Algorithms\lib\site-packages\orbit\utils\stan.py", line 62, in get_compiled_stan_model compiled_model = compile_stan_model(stan_model_name) File "C:\ProgramData\Anaconda3\envs\Temp\Forecasting_Algorithms\lib\site-packages\orbit\utils\stan.py", line 49, in compile_stan_model sm = StanModel(model_code=model_code) File "C:\ProgramData\Anaconda3\envs\Temp\Forecasting_Algorithms\lib\site-packages\pystan\model.py", line 378, in init build_extension.run() File "C:\ProgramData\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "C:\ProgramData\Anaconda3\lib\distutils\command\build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "C:\ProgramData\Anaconda3\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "C:\ProgramData\Anaconda3\lib\distutils\command\build_ext.py", line 533, in build_extension depends=ext.depends) File "C:\ProgramData\Anaconda3\lib\distutils\ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\ProgramData\Anaconda3\lib\distutils\cygwinccompiler.py", line 175, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'C:\MinGW\bin\gcc.exe' failed with exit status 1

    Environment (please complete the following information):

    • OS: Windows
    • Python Version: 3.6.5:: Anaconda, Inc.
    • Versions of Major Dependencies GCC: gcc (MinGW.org GCC Build-2) 9.2.0

    Let me know how I can resolve this issue. I appreciate the help from the community.

  • Occasional crash in distributed training and prediction of DLT models due to pystan

    Occasional crash in distributed training and prediction of DLT models due to pystan

    When I run roughly 10,000 different time series, I get runs crashing for various reasons. They typically only relate to two errors:

    pickle data was truncated or Ran out of input.

    Both seem to relate to stan compilation issues.

    Any tips on how to avoid these issues.

    I am running on ubuntu, with python 3.8 so don't think it's an OS issue.

  • Prediction is not thread-safe

    Prediction is not thread-safe

    Describe the bug I have a flask app that has an endpoint that looks something like this, where model is FullBayesianForecaster:

    @app.route("/predict", methods=["POST"])
    def predict():
        df = get_df()
        result = model.predict(df, seed=1234)
        return result.to_dict(orient="records")
    

    I tested it locally with curl and it worked great: the flask app returned the same predictions for the same input. I then deployed it to a test environment, and another service that talks to it immediately started getting non-deterministic results for requests with the same parameters. I checked the prediction results with another curl request to the test environment, and got the same result back every time, as expected.

    After scratching my head a bit, I tried using threading.Lock like this:

    with lock:
        result = model.predict(df, seed=1234)
    

    And then the non-determinism went away. This leads me to believe that model prediction is not thread safe. I haven't yet dug down far enough to know for sure what's causing the issue, but this seems to be at least one likely culprit:

    https://github.com/uber/orbit/blob/27371ec/orbit/forecaster/full_bayes.py#L96-L97

    If multiple threads are calling model.predict such that they fight over the value of self._prediction_meta here, that seems likely to cause predictions to be not thread-safe:

    https://github.com/uber/orbit/blob/c232980/orbit/forecaster/forecaster.py#L389

    To Reproduce

    Try running model.predict with different parameters in the presence of multiple threads, and set seed=a_fixed_number.

    Expected behavior

    Calling model.predict with seed=a_fixed_number in the presence of multiple threads returns deterministic predictions.

    Screenshots

    N/A

    Environment (please complete the following information):

    • OS: Ubuntu
    • Python Version: 3.9
    • Versions of Major Dependencies (pandas, scikit-learn, cython): [e.g. pandas==1.3.5, scikit-learn==<not installed>, cython==0.29.30]

    Additional context

    N/A

A probabilistic programming library for Bayesian deep learning, generative models, based on Tensorflow
A probabilistic programming library for Bayesian deep learning, generative models, based on Tensorflow

ZhuSuan is a Python probabilistic programming library for Bayesian deep learning, which conjoins the complimentary advantages of Bayesian methods and

Nov 28, 2022
A probabilistic programming language in TensorFlow. Deep generative models, variational inference.

Edward is a Python library for probabilistic modeling, inference, and criticism. It is a testbed for fast experimentation and research with probabilis

Nov 21, 2022
Deep universal probabilistic programming with Python and PyTorch
Deep universal probabilistic programming with Python and PyTorch

Getting Started | Documentation | Community | Contributing Pyro is a flexible, scalable deep probabilistic programming library built on PyTorch. Notab

Nov 28, 2022
Fast, flexible and easy to use probabilistic modelling in Python.
Fast, flexible and easy to use probabilistic modelling in Python.

Please consider citing the JMLR-MLOSS Manuscript if you've used pomegranate in your academic work! pomegranate is a package for building probabilistic

Nov 28, 2022
Project under the certification "Data Analysis with Python" on FreeCodeCamp
 Project under the certification

Sea Level Predictor Assignment You will anaylize a dataset of the global average sea level change since 1880. You will use the data to predict the sea

Jan 31, 2022
Probabilistic reasoning and statistical analysis in TensorFlow

TensorFlow Probability TensorFlow Probability is a library for probabilistic reasoning and statistical analysis in TensorFlow. As part of the TensorFl

Dec 5, 2022
Python Library for learning (Structure and Parameter) and inference (Statistical and Causal) in Bayesian Networks.

pgmpy pgmpy is a python library for working with Probabilistic Graphical Models. Documentation and list of algorithms supported is at our official sit

Dec 5, 2022
Functional tensors for probabilistic programming

Funsor Funsor is a tensor-like library for functions and distributions. See Functional tensors for probabilistic programming for a system description.

Nov 29, 2022
A forecasting system dedicated to smart city data

smart-city-predictions System prognostyczny dedykowany dla danych inteligentnych miast Praca inżynierska realizowana przez Michała Stawikowskiego and

Nov 8, 2021
Karate Club: An API Oriented Open-source Python Framework for Unsupervised Learning on Graphs (CIKM 2020)
Karate Club: An API Oriented Open-source Python Framework for Unsupervised Learning on Graphs (CIKM 2020)

Karate Club is an unsupervised machine learning extension library for NetworkX. Please look at the Documentation, relevant Paper, Promo Video, and Ext

Dec 2, 2022
PyChemia, Python Framework for Materials Discovery and Design
 PyChemia, Python Framework for Materials Discovery and Design

PyChemia, Python Framework for Materials Discovery and Design PyChemia is an open-source Python Library for materials structural search. The purpose o

Oct 2, 2022
PrimaryBid - Transform application Lifecycle Data and Design and ETL pipeline architecture for ingesting data from multiple sources to redshift
PrimaryBid - Transform application Lifecycle Data and Design and ETL pipeline architecture for ingesting data from multiple sources to redshift

Transform application Lifecycle Data and Design and ETL pipeline architecture for ingesting data from multiple sources to redshift This project is composed of two parts: Part1 and Part2

Jan 19, 2022
BAyesian Model-Building Interface (Bambi) in Python.

Bambi BAyesian Model-Building Interface in Python Overview Bambi is a high-level Bayesian model-building interface written in Python. It's built on to

Nov 20, 2022
pyhsmm MITpyhsmm - Bayesian inference in HSMMs and HMMs. MIT
pyhsmm MITpyhsmm - Bayesian inference in HSMMs and HMMs. MIT

Bayesian inference in HSMMs and HMMs This is a Python library for approximate unsupervised inference in Bayesian Hidden Markov Models (HMMs) and expli

Nov 21, 2022
Statistical Rethinking: A Bayesian Course Using CmdStanPy and Plotnine

Statistical Rethinking: A Bayesian Course Using CmdStanPy and Plotnine Intro This repo contains the python/stan version of the Statistical Rethinking

Nov 8, 2022
Using approximate bayesian posteriors in deep nets for active learning
Using approximate bayesian posteriors in deep nets for active learning

Bayesian Active Learning (BaaL) BaaL is an active learning library developed at ElementAI. This repository contains techniques and reusable components

Nov 28, 2022
A Python package for the mathematical modeling of infectious diseases via compartmental models
A Python package for the mathematical modeling of infectious diseases via compartmental models

A Python package for the mathematical modeling of infectious diseases via compartmental models. Originally designed for epidemiologists, epispot can be adapted for almost any type of modeling scenario.

Oct 11, 2022
A python package which can be pip installed to perform statistics and visualize binomial and gaussian distributions of the dataset

GBiStat package A python package to assist programmers with data analysis. This package could be used to plot : Binomial Distribution of the dataset p

Oct 17, 2022