diagnostics#
Diagnostics namespace — posterior/prior predictive and residual plots.
This module exposes DiagnosticsPlots, which is the entry point for all
time-series diagnostic plots on a fitted MMM model. It is accessed via
mmm.plot.diagnostics (a DiagnosticsPlots instance backed by the
model’s MMMIDataWrapper).
Examples#
Construct the plotter directly from the model’s data wrapper:
from pymc_marketing.mmm.plotting.diagnostics import DiagnosticsPlots
dp = DiagnosticsPlots(mmm.data)
Posterior predictive — overlay posterior mean, HDI band, and observed target:
fig, axes = dp.posterior_predictive()
# Scaled units, narrower HDI, two columns per row
fig, axes = dp.posterior_predictive(original_scale=False, hdi_prob=0.8, col_wrap=2)
Prior predictive — same layout drawn from the prior:
fig, axes = dp.prior_predictive()
fig, axes = dp.prior_predictive(original_scale=False, hdi_prob=0.8, col_wrap=2)
Residuals over time — mean residual line with HDI band and a zero reference:
fig, axes = dp.residuals_over_time()
# Subset to one geo, custom styling
fig, axes = dp.residuals_over_time(
hdi_prob=0.8,
dims={"geo": "geo_a"},
line_kwargs={"color": "red", "linestyle": "-."},
hdi_kwargs={"color": "red"},
)
Residuals distribution — KDE of the posterior residual distribution:
fig, axes = dp.residuals_distribution(figsize=(8, 4))
# Custom quantile markers, collapse geo into one distribution
fig, axes = dp.residuals_distribution(
figsize=(8, 4),
quantiles=[0.1, 0.5, 0.9],
aggregation="geo",
)
Posterior — 1-D marginal KDE for selected variables:
fig, axes = dp.posterior(["saturation_lam", "adstock_alpha"], figsize=(10, 8))
Prior vs posterior — overlaid prior and posterior KDEs:
fig, axes = dp.prior_vs_posterior(
["saturation_lam", "adstock_alpha"], figsize=(10, 8)
)
Classes
|
Time-series diagnostic plots for fitted MMM models. |