- Updated: January 31, 2026
- 7 min read
Going NUTS with ADVI: Exploring various Bayesian Inference techniques with Facebook Prophet
Direct Answer
The paper presents a full Bayesian reimplementation of Facebook Prophet using the PyMC probabilistic programming framework, enabling modern inference engines such as NUTS, ADVI, and MAP to replace Prophet’s original Stan‑based optimizer. This matters because it unlocks richer uncertainty quantification, faster experimentation with alternative priors, and seamless integration into Python‑centric data‑science pipelines.
Background: Why This Problem Is Hard
Time‑series forecasting is a cornerstone of many business‑critical applications—from demand planning to anomaly detection. Facebook Prophet gained popularity for its ease of use, automatic handling of seasonality, holidays, and trend changepoints, and for providing interpretable components. However, Prophet’s original implementation relies on a custom Stan model that is:
- Statically compiled, making rapid prototyping of new priors or likelihoods cumbersome.
- Limited to a single inference algorithm (Hamiltonian Monte Carlo via Stan’s NUTS), which can be slow on large datasets.
- Opaque in terms of posterior diagnostics, leaving practitioners uncertain about convergence or model misspecification.
These constraints clash with today’s demand for flexible, reproducible, and scalable Bayesian workflows. Data scientists increasingly expect to experiment with variational inference, MAP estimation, or custom hierarchical priors without rewriting low‑level Stan code. Moreover, production systems that orchestrate multiple forecasting agents need a common Pythonic interface to plug in different inference back‑ends, something Prophet’s original architecture does not readily support.
What the Researchers Propose
The authors introduce Prophet‑PyMC, a drop‑in replacement for the original library that re‑expresses Prophet’s generative model in PyMC’s declarative syntax. The key components are:
- Trend Module: A piecewise linear or logistic growth model with automatically detected changepoints, now expressed as stochastic variables with configurable priors.
- Seasonality Module: Fourier series terms for yearly, weekly, and daily cycles, each wrapped as PyMC random variables, allowing hierarchical sharing of amplitudes across seasons.
- Holiday Effects: A sparse matrix of holiday indicators modeled with a hierarchical prior, enabling borrowing strength across similar holidays.
- Observation Model: A flexible likelihood that can be swapped (e.g., Gaussian, Student‑t, Poisson) without touching the core code.
By decoupling model specification from inference, the framework lets users select from multiple engines—NUTS for full posterior sampling, ADVI for fast variational approximations, or MAP for point estimates—through a single API call.
How It Works in Practice
The workflow follows a clear, modular pipeline:
- Data Ingestion: A pandas DataFrame with timestamps and observed values is passed to
ProphetPyMC. The library automatically creates the design matrices for trend, seasonality, and holidays. - Model Construction: Using PyMC’s
Modelcontext, the code declares stochastic nodes for each component. Priors are either the defaults from the original Prophet paper or user‑provided alternatives. - Inference Selection: The user specifies the inference method via a parameter (e.g.,
method="nuts","advi", or"map"). Under the hood, PyMC dispatches to the appropriate sampler or optimizer. - Sampling / Optimization: For NUTS, the sampler draws multiple chains, automatically tuning step sizes. ADVI runs stochastic gradient descent on the evidence lower bound, producing an approximate posterior. MAP performs gradient‑based maximization of the joint posterior.
- Posterior Diagnostics: PyMC returns trace objects that can be inspected with built‑in diagnostics (R‑hat, effective sample size) and visualized via
arviz. This step is optional for MAP/ADVI but recommended for NUTS. - Forecast Generation: The posterior predictive distribution is sampled (or approximated) for future timestamps, yielding both point forecasts and credible intervals.
What distinguishes this approach is the seamless interchangeability of inference engines without altering the model definition—a stark contrast to Prophet’s monolithic Stan backend. Additionally, because the model lives in pure Python, it integrates naturally with existing data‑science stacks, CI pipelines, and containerized deployments.
Evaluation & Results
The authors benchmarked Prophet‑PyMC against the original Prophet on three publicly available time‑series datasets: (1) a retail sales series with strong weekly seasonality, (2) a web‑traffic series exhibiting abrupt changepoints, and (3) a synthetic dataset with known ground‑truth parameters. Evaluation focused on three axes:
- Predictive Accuracy: Measured by Mean Absolute Percentage Error (MAPE) and Continuous Ranked Probability Score (CRPS) for probabilistic forecasts.
- Uncertainty Calibration: Assessed via prediction interval coverage probability (PICP) to see if 95 % intervals contain the true values at the expected rate.
- Computational Efficiency: Wall‑clock time and memory consumption for each inference method.
Key findings include:
- All three inference methods (NUTS, ADVI, MAP) produced forecasts comparable in MAPE to the original Prophet, with NUTS slightly better on the synthetic dataset where full posterior exploration mattered.
- ADVI achieved a 5‑10× speedup over NUTS while preserving well‑calibrated intervals (PICP ≈ 94 % vs. 95 % for NUTS), making it attractive for rapid prototyping.
- MAP delivered the fastest runtimes (sub‑second for modest datasets) but yielded under‑dispersed intervals, highlighting the trade‑off between speed and uncertainty quantification.
- Custom priors (e.g., tighter variance on changepoint magnitudes) were easily injected, leading to measurable improvements in forecast stability for the retail series.
Overall, the experiments demonstrate that Prophet‑PyMC matches or exceeds the original’s predictive performance while offering a spectrum of inference choices that can be tuned to the operational constraints of a given application.
Why This Matters for AI Systems and Agents
Forecasting components are increasingly being wrapped as autonomous agents within larger decision‑making pipelines—think inventory‑replenishment bots, dynamic pricing engines, or anomaly‑detection services. Prophet‑PyMC’s design aligns with this trend in several ways:
- Modular API: Agents can request a forecast by specifying the desired inference method, allowing the same model to serve both low‑latency (MAP) and high‑certainty (NUTS) scenarios.
- Interoperability: Because the model lives in PyMC, it can be combined with other probabilistic components (e.g., Bayesian hierarchical demand models) within a single probabilistic program, simplifying end‑to‑end Bayesian pipelines.
- Scalable Orchestration: Cloud‑native orchestration platforms can spin up separate workers for heavy NUTS sampling while keeping lightweight MAP workers on the edge, optimizing resource allocation.
- Transparency: Built‑in diagnostics empower system operators to monitor convergence and detect model drift, reducing silent failures in production agents.
For teams building AI‑driven products, this means faster iteration cycles, better risk management through calibrated uncertainty, and a unified Pythonic stack that reduces the operational overhead of maintaining multiple forecasting tools. Learn more about integrating Bayesian agents on our agents platform.
What Comes Next
While Prophet‑PyMC marks a significant step forward, several avenues remain open for research and engineering:
- Scalable Sampling: Leveraging GPU‑accelerated HMC or distributed NUTS could shrink runtimes for massive time‑series collections.
- Automatic Prior Selection: Meta‑learning techniques could infer sensible priors from historical series, reducing the manual tuning burden.
- Hybrid Likelihoods: Extending the observation model to handle zero‑inflated or count‑heavy data (e.g., using a hurdle model) would broaden applicability.
- Real‑Time Updating: Implementing sequential Monte Carlo or streaming variational inference would enable forecasts that adapt on the fly as new data arrives.
- Integration with MLOps: Packaging Prophet‑PyMC as a reusable component in model registries and CI/CD pipelines can further streamline deployment.
Addressing these challenges will cement Bayesian time‑series forecasting as a first‑class citizen in modern AI ecosystems. For developers interested in contributing to the next generation of forecasting agents, our roadmap and contribution guidelines are available on the project roadmap page.
Read the full technical details in the original preprint: Prophet‑PyMC: A Bayesian Reimplementation of Facebook Prophet with Modern Inference Engines.