Hands-On Guide To Orbit: Uber’s Python Framework For Bayesian Forecasting & Inference

Orbit is an open-source Python framework created by Uber for Bayesian time series forecasting and inference.
Orbit feature image

Although several machine learning and deep learning models have been adopted for time series forecasting tasks, parametric statistical approaches like ARIMA still reign supreme while dealing with low granularity data. Orbit is a Python framework created by Uber for Bayesian time series forecasting and inference; it is built upon probabilistic programming packages like PyStan and Uber’s own Pyro. Orbit currently supports the implementations of the following forecasting 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

Orbit refined two of the models, namely DLT and LGT. These tweaked models were compared with popular time series models such as SARIMA and Facebook Prophet. Symmetric mean absolute percentage error (SMAPE) was used as the forecast metric for comparing these models. 

Subscribe to our Newsletter

Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy
Your newsletter subscriptions are subject to AIM Privacy Policy and Terms and Conditions.
Symmetric mean absolute percentage error (SMAPE)

Here Xt is the value measured at time t, and h is the forecast horizon.

The benchmark study was conducted on five datasets:

  •  US and Canada rider first-trips with Uber (20 weekly series by city)
  •  US and Canada driver weekly first-trips with Uber (20 weekly series by city)
  •  Worldwide first-orders with Uber Eats(15 daily series by country)
  • M3 series (1428 monthly series)
  • M4 series (359 weekly series)
Orbit’s refined models vs Prophet and SARIMA

Orbit’s refined models consistently deliver better accuracy than the other time series models in terms of SMAPE.

Implementing Damp Local Trend models with Orbit

  1. Install orbit from PyPI

!pip install orbit-ml

For other installation, methods see this.

  1. Import necessary libraries and classes.
 import pandas as pd
 import numpy as np
 from datetime import timedelta
 from orbit.models.dlt import DLTMAP, DLTAggregated, DLTFull
 from orbit.diagnostics.plot import plot_predicted_data
 from orbit.diagnostics.plot import plot_predicted_components
 from orbit.utils.dataset import load_iclaims 
  1. Load the data for forecasting.

We are going to use the iclaims_example dataset provided by Orbit. It contains the weekly initial claims for US unemployment benefits against a few related google trend queries (unemploy, filling, and job)from Jan 2010 – June 2018.

 # load data
 df = load_iclaims()
 date_col = 'week'
 response_col = 'claims'
 #split the dataset
 test_size = 52
 train_df = df[:-test_size]
 test_df = df[-test_size:] 
  1. Create and train the DLT models.

We will try out the three different wrappers for the Damped Local Trend model provided in Orbit-  DLTMAP, DLTAggregated, and  DLTFull.

  • DLT model for MAP (Maximum a Posteriori) prediction
 #define the DLTMAP model
 dlt = DLTMAP(

 #train the model

 #make inference
 predicted_df = dlt.predict(df=test_df)

 #Plot the results
 _ = plot_predicted_data(training_actual_df=train_df, predicted_df=predicted_df, 
                     date_col=date_col, actual_col=response_col,  
                     test_actual_df=test_df, title='Prediction with DLTMAP Model') 
Prediction with DLTMAP Model
  • DLTFull

In full prediction, the prediction occurs as a function of each parameter posterior sample, and the prediction results are aggregated after prediction.

 #define the DLTFull model
 dlt = DLTFull(

 #train the model

 #make inference
 predicted_df = dlt.predict(df=test_df)

 #plot results
 _ = 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, title='Prediction with DLTFull Model') 
Prediction with DLTFull Model
  • DLTAggregated

In aggregated prediction, the parameter posterior samples are reduced using aggregate_method ({ 'mean', 'median' }) before performing a single prediction.

 #define the DLTAggregated model
 dlt = DLTAggregated(

 #train the model

 #make inference
 predicted_df = dlt.predict(df=test_df)

 #plot results
 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, title='Prediction with DLTAggregated Model') 
Prediction with DLTAggregated Model

More information about the different models is available here.

Code for the above implementation has been taken from the official example notebook available here.

Last Epoch (Endnote)

This article introduced Orbit, Uber’s open-source Python library for time series forecasting. With the help of the underlying probabilistic programming packages, Orbit introduces multiple model refinements like additional global trends, transformation for multiplicative form, noise distribution, and priors’ choice. These refined models outperform other common forecasting models like SARIMA and Facebook Prophet. As per the paper, the developers are adding new models and features like dual seasonality support, full Pyro integration, etc.

To better understand the mathematics behind the refinements and to know more about the different models and methods provided by Orbit, see:

Aditya Singh
A machine learning enthusiast with a knack for finding patterns. In my free time, I like to delve into the world of non-fiction books and video essays.

Download our Mobile App

MachineHack | AI Hackathons, Coding & Learning

Host Hackathons & Recruit Great Data Talent!

AIMResearch Pioneering advanced AI market research

With a decade of experience under our belt, we are transforming how businesses use AI & data-driven insights to succeed.

The Gold Standard for Recognizing Excellence in Data Science and Tech Workplaces

With Best Firm Certification, you can effortlessly delve into the minds of your employees, unveil invaluable perspectives, and gain distinguished acclaim for fostering an exceptional company culture.

AIM Leaders Council

World’s Biggest Community Exclusively For Senior Executives In Data Science And Analytics.

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox