Tutorial

Build a Bayesian Marketing Mix Model with Google Meridian

Step-by-step guide to building a Bayesian marketing mix model with Google Meridian: data loading, ROI priors, NUTS sampling, and budget optimisation.

LUMIEN5 min read
Build a Bayesian Marketing Mix Model with Google Meridian

Google Meridian is an open-source marketing mix modelling (MMM) library built on TensorFlow that uses Bayesian inference to measure channel ROI and optimise media budgets. This tutorial walks through the full workflow: installing Meridian with GPU-backed TensorFlow, loading a geo-level simulated dataset with five paid channels, mapping columns to the Meridian schema, setting LogNormal ROI priors, running NUTS posterior sampling across seven chains, evaluating convergence with R-hat diagnostics, and using the built-in Analyzer and Optimizer APIs for budget decisions.

What happened

The tutorial published by Marktechpost walks through a complete end-to-end marketing mix model built with Google Meridian. It covers every stage from environment setup to a fitted, exportable model ready for budget planning.

Detail Value
Library google-meridian[and-cuda]
Backend TensorFlow + TensorFlow Probability
Dataset Simulated geo-level CSV (5 paid channels, 1 organic)
Prior distribution LogNormal(mu=0.2, sigma=0.9) on ROI
Posterior sampler NUTS, 7 chains, 500 adapt, 500 burn-in, 1,000 kept draws
Convergence target R-hat below 1.05
Prior samples 500

How the workflow is structured

1. Data loading and schema mapping

The simulated dataset includes media impressions, spend, control variables (competitor sales and sentiment score), a promotional treatment, conversions as the KPI, population, and revenue per conversion. Meridian uses a CoordToColumns object to map your raw column names to its internal schema. Five impression columns and five spend columns are mapped to Channel 0 through Channel 4. One organic media channel and one non-media treatment (a promotion flag) are also registered.

The CsvDataLoader then produces an InputData object with a media tensor shaped as (geo, time, channel). Getting this mapping right before touching any model code saves a lot of debugging time.

2. ROI priors and model configuration

Rather than flat or vague priors, the tutorial sets a LogNormal(0.2, 0.9) prior on the ROI parameter for each media channel. LogNormal is a sensible choice here because ROI cannot be negative and the distribution captures the right-skew common in media data. The prior is passed into a ModelSpec, which is then used to initialise the Meridian model object.

3. Sampling and convergence

Meridian uses the No-U-Turn Sampler (NUTS), a variant of Hamiltonian Monte Carlo that adapts its step size automatically and is well suited to high-dimensional posterior distributions. The tutorial runs 500 prior samples first, then the posterior across 7 parallel chains with 500 adaptation steps, 500 burn-in steps, and 1,000 kept draws per chain.

After sampling, the ModelDiagnostics visualiser plots an R-hat boxplot. R-hat (the Gelman-Rubin statistic) measures whether the chains have mixed well. Values below 1.05 indicate reliable convergence. The tutorial also compares prior and posterior distributions for the ROI parameters to show how much the data has updated the model’s beliefs.

4. Media analysis and channel metrics

Once the model fits, the MediaSummary class produces a set of standard outputs. These include:

  • Outcome decomposition over time, split into baseline and per-channel contributions
  • Spend share versus contribution share, which flags channels that are over- or under-invested relative to their output
  • ROI bar charts with credible intervals (the Bayesian equivalent of confidence intervals)
  • A ROI versus effectiveness bubble chart, where bubble size represents total spend
  • ROI versus marginal ROI (mROI), the return on the next incremental dollar, which is what actually drives optimisation decisions
  • Adstock and saturation curves, which show how media effects decay over time and how spend efficiency falls as volume increases

5. Budget optimisation and export

The Optimizer API handles two scenarios: a fixed total budget (reallocate spend across channels) and a flexible budget (find the spend level that maximises returns). Results are exportable as HTML reports. The fitted model object can be saved and reloaded, so you are not forced to re-run sampling every time you want to explore a new budget scenario.

Why it matters for your media planning

Traditional last-click attribution assigns 100% of a conversion to the final touchpoint and ignores everything else. MMM, by contrast, uses historical data across all channels simultaneously to estimate each channel’s true contribution, including the effect of TV, out-of-home, or any channel that does not produce a trackable click. The Bayesian approach adds something rule-based regression cannot: honest uncertainty. Every ROI estimate comes with a credible interval, so you know how confident the model actually is.

For advertisers running paid search and display campaigns alongside other channels, this kind of model can surface the contribution of brand spend that never gets credit in platform attribution reports. The marginal ROI metric is particularly useful: if a channel’s average ROI is high but its mROI is low, you are already past the point of efficient spending on that channel.

Our take

Meridian is a serious library and this tutorial is genuinely thorough. The R-hat convergence check and the prior-versus-posterior comparison are not optional extras; they are what separates a trustworthy Bayesian model from a black box. If R-hat is above 1.05 on key parameters, the results should not be used to move budget.

The practical limitation most teams will hit is compute. NUTS sampling across 7 chains is slow on CPU. A GPU runtime (Colab A100 or equivalent) cuts it to minutes. The other real-world challenge is data quality: Meridian’s simulated dataset is clean and complete. Your actual marketing data probably has gaps, channel name inconsistencies, and spend reported at different granularities than impressions. Plan for that mapping work to take longer than the modelling itself.

For teams that want to move beyond last-click attribution, exploring AI integration into your analytics stack is a natural next step. MMM is not a weekend project, but the open-source tooling has matured to the point where a competent data team can ship a working model in a few weeks rather than months.

What to do about it

  1. Check whether you have at least 2 years of weekly channel spend and KPI data before starting. MMM needs sufficient variation to identify effects reliably.
  2. Run pip install google-meridian[and-cuda] in a GPU-enabled environment and load your data through CsvDataLoader before defining any priors.
  3. Inspect R-hat values after sampling. If any parameter shows R-hat above 1.05, increase n_adapt or n_burnin before trusting the outputs.
  4. Compare marginal ROI across channels, not just average ROI, when making reallocation decisions.
  5. Save the fitted model object so you can run new budget scenarios without resampling.

Start with the marginal ROI chart: it is the single output most likely to change where your next media dollar goes.

Source: Marktechpost

Frequently asked questions

What is Google Meridian and how does it work?

Google Meridian is an open-source Bayesian marketing mix modelling library built on TensorFlow and TensorFlow Probability. It estimates each media channel's contribution to a KPI using NUTS posterior sampling, which produces ROI estimates with credible intervals rather than single point estimates.

Do I need a GPU to run Google Meridian?

A GPU is not strictly required, but the tutorial explicitly warns that NUTS sampling will be slow on CPU. The library installs with CUDA support via pip install google-meridian[and-cuda], and a GPU runtime such as a Colab A100 is recommended for practical run times.

What is marginal ROI and why does it matter in MMM?

Marginal ROI (mROI) is the return generated by the next incremental dollar spent on a channel. It differs from average ROI and is the metric that drives budget optimisation decisions. A channel can have a high average ROI but a low mROI if spend has already pushed it past its efficient range.

How do I know if my Bayesian marketing mix model has converged?

The standard diagnostic is the R-hat (Gelman-Rubin) statistic. Values below 1.05 indicate that the sampling chains have mixed well and the results are reliable. Google Meridian's ModelDiagnostics visualiser produces an R-hat boxplot for this check.

More from Advertising