Written and maintained by CASRAI Editorial Board
Published
On this page
PyMC-Marketing is an open-source Python library for Bayesian marketing analytics, built on PyMC and developed by PyMC Labs under the Apache-2.0 licence. Its best-known component is marketing mix modeling (MMM): a regression that relates weekly sales or another outcome to media spend, after adjusting for delayed (adstock) and diminishing (saturation) advertising effects, with every parameter reported as a posterior distribution instead of a single estimate.
What is PyMC-Marketing?
The project describes itself as a Bayesian marketing analytics toolbox on top of PyMC (GitHub repository, read 2026-11-18). A peer-reviewed software paper, PyMC-Marketing: Bayesian Marketing Mix Models and Customer Analytics in Python, appeared in the Journal of Open Source Software on 27 August 2026 (JOSS record; DOI 10.21105/joss.10805). Because it sits on PyMC, its models are fitted by Markov chain Monte Carlo, so the same ideas apply as in any other Bayesian workflow; see the CASRAI guides on Markov chain Monte Carlo and Bayesian regression for the background.
It is not a single model. The repository lists several families, summarised in the table below.
| Area | What the repository lists |
|---|---|
| Marketing mix modeling (MMM) | Adstock and saturation transforms, time-varying intercepts and media effects, budget optimization, calibration with lift tests and ROAS/CAC information, funnel models, VARX long-term brand effects, causal identification and out-of-sample prediction |
| Customer lifetime value (CLV) | BG/NBD, Pareto/NBD, Gamma-Gamma, Shifted BG and Modified BG/NBD models |
| Customer choice | MVITS, multinomial, nested, mixed and consideration-set logit, MaxDiff and Bayesian BLP |
| Bass diffusion | Bass diffusion models |
| PIE | Marked alpha status in the repository: its API may change |
Every row comes from the repository page; the maturity note for PIE is the project’s own.
How do you install PyMC-Marketing, and what does it require?
Install it with pip install pymc-marketing. The repository states that it needs Python 3.12 or newer and builds on PyMC 6.0 or newer and ArviZ 1.2 or newer (with the arviz-plots package). Optional extras are named [dag], [pie] and [var], and a Dockerfile is provided (repository README, read 2026-11-18). An older environment pinned to Python 3.11 or to PyMC 5 will therefore need upgrading before the current release installs.
What is the model equation behind PyMC-Marketing’s MMM?
The documented example describes a linear model with media transforms. In words: the outcome in week t equals an intercept, plus, for each media channel m, a coefficient multiplied by the transformed spend of that channel, plus control terms and Fourier seasonality, plus noise (MMM example notebook, read 2026-11-18). Written compactly, yt = α + Σm βm · f(xm,t) + controls + seasonality + εt, where xm,t is spend on channel m in week t and f is the adstock-then-saturation transformation.
Each part of the equation maps to an argument in the library’s MMM class:
- Adstock (carry-over of advertising into later weeks):
adstock=GeometricAdstock(l_max=8)in the notebook, wherel_maxis the maximum lag in weeks. - Saturation (diminishing returns):
saturation=LogisticSaturation(). - Channels:
channel_columns=["x1", "x2"], the spend columns. - Controls:
control_columns=["event_1", "event_2", "t"], covariates such as events and a trend. - Seasonality:
yearly_seasonality=2, the number of Fourier terms. - Time index:
date_column="date_week".
What do the default and custom priors look like?
Bayesian MMM needs priors for every transform parameter. The notebook lists defaults for the three transform parameters, shown in the data table below this page. It then overrides several priors to show how domain knowledge enters the model:
| Parameter in the notebook | Custom prior used |
|---|---|
| Intercept | Normal(0.5, 0.2) |
| saturation_beta | HalfNormal with sigma = n_channels × spend share, one value per channel |
| gamma_control | Normal(0, 0.05) |
| gamma_fourier | Laplace(0, 0.2) |
| Likelihood | Normal, with sigma given a HalfNormal(6) prior |
The point is the design choice: the spend-share scaling of the saturation coefficient ties the prior for each channel’s effect to how much money that channel receives. Choosing priors this way is a judgement that should be reported with the model, and the notebook also runs a prior predictive check (mmm.sample_prior_predictive(X, y, samples=2_000)) before fitting to see whether the priors imply plausible outcomes.
Worked example: adstock arithmetic
Geometric adstock carries a fraction α of the previous period’s accumulated effect forward. As an illustration of the idea only (the library’s own implementation truncates at l_max and has further options, so use its documentation for the exact form), take α = 0.4 and spend of 100 in week 1 and zero afterwards, using a_t = xt + α · at−1:
- Week 1: a1 = 100 + 0.4 × 0 = 100
- Week 2: a2 = 0 + 0.4 × 100 = 40
- Week 3: a3 = 0 + 0.4 × 40 = 16
- Week 4: a4 = 0 + 0.4 × 16 = 6.4
The effect of a single burst decays by a factor of 0.4 each week. The notebook’s simulated data used adstock α values of 0.4 and 0.2 for its two channels, saturation λ of 4.0 and 3.0, and β of 3.0 and 2.0, so you can compare the fitted posterior with known truth.
How do you fit a model in Python?
The notebook builds and fits the model with the calls below (imports as listed in the notebook; X is the data frame of dates, spend and controls and y the outcome):
import pymc as pm
from pymc_marketing.mmm import GeometricAdstock, LogisticSaturation
from pymc_marketing.mmm.mmm import MMM
mmm = MMM(
date_column="date_week",
adstock=GeometricAdstock(l_max=8),
saturation=LogisticSaturation(),
channel_columns=["x1", "x2"],
control_columns=["event_1", "event_2", "t"],
yearly_seasonality=2,
)
mmm.build_model(X, y)
mmm.fit(X=X, y=y, chains=4, tune=1_500, draws=1_000,
target_accept=0.9, random_seed=rng)
The notebook also passes model_config and sampler_config to override priors and sampler settings.
How do you read the output?
After fitting, the notebook runs four checks, which make a usable checklist:
| Check | Call in the notebook | What the notebook reports |
|---|---|---|
| Divergences | mmm.idata["sample_stats"]["diverging"].sum() |
Zero divergent transitions |
| Summary and r_hat | az.summary(...) |
r_hat of 1.00 for most parameters and 1.01 for a few; it states no threshold |
| Trace plots | azp.plot_trace_dist(...) |
“Overall we see a good chain mixing” |
| Posterior predictive | mmm.sample_posterior_predictive(X=X, ...) |
4,000 samples for y and y_original_scale |
Contribution estimates are available on the original scale after calling mmm.add_original_scale_contribution_variable(...), which creates channel_contribution_original_scale. Because the example data were simulated, the notebook can confirm that the estimated adstock and saturation parameters are very close to those used to generate the data. With real data no such truth exists, so the checks above and sensitivity to the priors are the evidence you have.
What is stored in the fitted model?
The fitted object keeps the full posterior, which is why the output is a distribution rather than a point estimate. In the notebook the posterior group holds adstock_alpha, saturation_lam, saturation_beta and y_sigma, one set of draws per parameter and, for the channel-level parameters, one per channel. The sampler record holds the divergence flags, and the contribution variable channel_contribution_original_scale gives each channel’s modelled contribution in the units of the outcome. Because every quantity has draws, any summary you quote (a channel’s contribution, a decay rate) can be given with an interval. The repository also lists budget optimization and calibration against lift-test and ROAS or CAC information among the MMM features, which build on the same posterior.
That interval is the practical difference from a least-squares fit: two channels whose coefficient intervals overlap heavily should not be ranked confidently against each other, however different the point estimates look. Report the interval, not only the mean.
Assumptions and common mistakes
- Treating the posterior as causal by default. MMM is observational regression. The library lists lift-test calibration and causal identification among its features precisely because spend that moves with demand can mislead; see the CASRAI guide on causal analysis.
- Skipping the prior predictive check. Priors on the saturation coefficient and likelihood scale determine what the model finds plausible before it sees data.
- Ignoring sampler warnings. Divergences and r_hat values are the first things the notebook inspects.
- Environment mismatch. The Python 3.12 and PyMC 6 requirements apply to the current repository version.
How do you report a PyMC-Marketing analysis?
State the software, version, priors, sampler settings (chains, tuning steps, draws, target acceptance) and the diagnostics. Cite the software paper; the journal record gives the title above and the DOI 10.21105/joss.10805, and the full author list is on the JOSS page. For example: “We fitted a Bayesian marketing mix model with PyMC-Marketing (geometric adstock with l_max = 8, logistic saturation; four chains, 1,000 draws after 1,500 tuning steps, target acceptance 0.9) and found no divergent transitions.” Take the version number from your own environment.
Sources
- PyMC Labs, pymc-marketing repository (README), read 2026-11-18
- PyMC-Marketing documentation, MMM example notebook, read 2026-11-18
- Journal of Open Source Software, PyMC-Marketing paper record, read 2026-11-18
- DOI 10.21105/joss.10805
- CASRAI: Bayesian hierarchical models
Data: PyMC-Marketing default priors for the MMM transform parameters
Default prior distributions that the PyMC-Marketing MMM example notebook lists for its adstock and saturation parameters, compiled from the project's documentation as read in November 2026.
| Parameter | Transform | Default prior | Prior parameters |
|---|---|---|---|
| adstock_alpha | Geometric adstock | Beta | 1, 3 |
| saturation_lam | Logistic saturation | Gamma | 3, 1 |
| saturation_beta | Logistic saturation | HalfNormal | 2 |
Sources
- PyMC-Marketing MMM example notebook (accessed 2026-11-18)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







