PyMC-Marketing: Open Source Bayesian Marketing Mix Modeling & CLV in Python#
PyMC-Marketing is an open-source Python library for Bayesian marketing analytics, built and maintained by PyMC Labs. It provides production-ready implementations of Marketing Mix Modeling (MMM) and Customer Lifetime Value (CLV) models, enabling data scientists to measure media effectiveness, optimize marketing spend, and forecast customer value — all with full Bayesian uncertainty quantification. Whether you call it marketing mix modeling or media mix modeling, PyMC-Marketing is the most comprehensive open-source MMM solution available in Python.
Powered by
Get started#
pip install pymc-marketing
from pymc_marketing.mmm import GeometricAdstock, LogisticSaturation, MMM
mmm = MMM(
adstock=GeometricAdstock(l_max=8),
saturation=LogisticSaturation(),
date_column="date_week",
channel_columns=["x1", "x2"],
control_columns=["event_1", "event_2", "t"],
yearly_seasonality=2,
)
See how PyMC-Marketing compares to Google Meridian, Meta Robyn, and other MMM frameworks, or read the benchmark comparison to Meridian.
Quick links#
Browse our getting started guide to quickly get started with PyMC-Marketing.
The example notebooks provide examples of using the library in both real case scenarios and synthetic data. They explain how to use the library and showcase its features.
The reference guide contains a detailed description of the functions, modules, and objects included in the library. The reference describes how the methods work and which parameters can be used. It assumes that you have an understanding of the key concepts.
Bayesian Marketing Mix Modeling (MMM) in PyMC#
Leverage our Bayesian MMM API to tailor your marketing strategies effectively. Leveraging on top of the research article Jin, Yuxue, et al. “Bayesian methods for media mix modeling with carryover and shape effects.” (2017), and extending it by integrating the expertise from core PyMC developers, our API provides:
Feature |
Benefit |
|---|---|
Custom Priors and Likelihoods |
Tailor your model to your specific business needs by including domain knowledge via prior distributions. |
Adstock Transformation |
Optimize the carry-over effects in your marketing channels. |
Saturation Effects |
Understand the diminishing returns in media investments. |
Customize adstock and saturation functions |
You can select from a variety of adstock and saturation functions. You can even implement your own custom functions. See documentation guide. |
Time-varying Intercept |
Capture time-varying baseline contributions in your model (using modern and efficient Gaussian processes approximation methods). See guide notebook. |
Time-varying Media Contribution |
Capture time-varying media efficiency in your model (using modern and efficient Gaussian processes approximation methods). See the guide notebook. |
Visualization and Model Diagnostics |
Get a comprehensive view of your model’s performance and insights. |
Choose among many inference algorithms |
We provide the option to choose between various NUTS samplers (e.g. BlackJax, NumPyro and Nutpie). See the example notebook for more details. |
GPU Support |
PyMC’s multiple backends allow for GPU acceleration. |
Out-of-sample Predictions |
Forecast future marketing performance with credible intervals. Use this for simulations and scenario planning. |
Budget Optimization |
Allocate your marketing spend efficiently across various channels for maximum ROI. See the budget optimization example notebook |
Experiment Calibration |
Fine-tune your model based on empirical experiments for a more unified view of marketing. See the lift test integration explanation for more details. Here you can find a Case Study: Unobserved Confounders, ROAS and Lift Tests. |
Unlock Customer Lifetime Value (CLV) with PyMC#
Understand and optimize your customer’s value with our CLV models. Our API supports various types of CLV models, catering to both contractual and non-contractual settings, as well as continuous and discrete transaction modes:
Each of these models is tailored to different types of data and business scenarios:
Non-contractual |
Contractual |
|
|---|---|---|
Continuous |
online purchases |
ad conversion time |
Discrete |
concerts & sports events |
recurring subscriptions |
Customer Choice Analysis#
Analyze the impact of new product launches and understand customer choice behavior with our Multivariate Interrupted Time Series (MVITS) models. Our API supports analysis in both saturated and unsaturated markets to help you:
Feature |
Benefit |
|---|---|
Market Share Analysis |
Understand how new products affect existing product market shares |
Causal Impact Assessment |
Measure the true causal effect of product launches on sales |
Saturated Market Analysis |
Model scenarios where total market size remains constant |
Unsaturated Market Analysis |
Handle cases where new products grow the total market size |
Visualization Tools |
Plot market shares, causal impacts, and counterfactuals |
Bayesian Inference |
Get uncertainty estimates around all predictions |
See our example notebooks for saturated markets and unsaturated markets to learn more about customer choice modeling with PyMC-Marketing.
Bass Diffusion Model#
Forecast the adoption of new products with the Bass Diffusion Model. The model captures how innovators and imitators drive cumulative adoption over time, which is useful for product launch forecasts, demand planning, and growth analysis.
See the Bass Diffusion Model example notebook for a worked example.
Resources#
Bolt’s success story with PyMC-Marketing#
Checkout the video below to see how Bolt leverages PyMC-Marketing to assess the impact of their marketing efforts.
Time-varying parameters in MMMs in PyMC-Marketing#
Customer Lifetime Value Modeling in Marine Industry#
For more videos, webinars and resources, check out the PyMC Labs YouTube channel.
More PyMC Labs Blog Posts and Resources#
Marketing Mix Models#
Customer Lifetime Value#
Case Studies#
Bayesian Media Mix Models: Modelling changes in marketing effectiveness over time
Improving the Speed and Accuracy of Bayesian Media Mix Models
Bayesian inference at scale: Running A/B tests with millions of observations
For more blogposts and resources, check out the PyMC Labs Blog.
Frequently Asked Questions#
What is PyMC-Marketing?#
PyMC-Marketing is an open-source Python library for Bayesian marketing analytics. It includes production-ready implementations of Marketing Mix Modeling (MMM) for measuring media effectiveness and optimizing marketing spend, Customer Lifetime Value (CLV) models for forecasting customer value over time, Customer Choice models for analyzing product launch impacts, and a Bass Diffusion Model for forecasting new product adoption.
How does PyMC-Marketing compare to Google Meridian or Meta Robyn?#
PyMC-Marketing is the only open-source framework that combines MMM, CLV, Customer Choice, and Bass Diffusion models in a single library, with full Bayesian uncertainty quantification via PyMC. Unlike Robyn (frequentist ridge regression) or Meridian (limited to MMM), PyMC-Marketing gives you posterior distributions over all parameters, custom priors for incorporating domain knowledge, and a unified API across all model types. See the full comparison and the benchmark comparison to Meridian.
Is PyMC-Marketing free to use?#
Yes. PyMC-Marketing is completely free and open source under the Apache 2.0 license. You can install it with pip install pymc-marketing.
What Python version does PyMC-Marketing require?#
PyMC-Marketing supports Python 3.12 and above.
Can PyMC-Marketing optimize my marketing budget?#
Yes. PyMC-Marketing includes built-in budget optimization that allocates spend across channels to maximize ROI, accounting for diminishing returns via saturation curves and carry-over effects via adstock transformations.
Need help with PyMC-Marketing?#
Book a free 30-minute strategy session with our experts or send us a message.