Fitting the Model
Use this page after you have prepared X and y for PanelMMM. For input
requirements, see Data Preparation.
Basic workflow
fit() is the main entry point for posterior sampling.
fit() returns an arviz.InferenceData object and also stores it on
mmm.idata.
What fit() does
When you call fit(X, y), Abacus:
- checks that pandas
Xandyuse the same index, if both are pandas objects - builds the PyMC graph automatically if it has not been built already
- merges sampler settings from the model’s
sampler_configand your call-time kwargs - runs
pymc.sample(...) - computes deterministic variables and adds them to the posterior group
- stores the training data in an
InferenceData.fit_datagroup - writes model metadata into
idata.attrs
That means fitted contribution variables such as channel_contribution,
intercept_contribution, and yearly_seasonality_contribution are available
in mmm.posterior after fitting when they are part of the configured model.
Configure the sampler
You can configure PyMC sampling in two places:
| Where | Use it for | Precedence |
|---|---|---|
sampler_config= in PanelMMM(...) |
Stable defaults you want to reuse across fits | Lower |
fit(..., **kwargs) |
Run-specific overrides such as draws, chains, or random_seed |
Higher |
Abacus merges them so that explicit fit() kwargs win.
Common sampler arguments
These are passed through to pymc.sample(...).
| Argument | What it controls |
|---|---|
draws |
Posterior samples kept after tuning |
tune |
Warm-up or adaptation iterations |
chains |
Number of MCMC chains |
cores |
Number of worker processes used by PyMC |
target_accept |
HMC or NUTS acceptance target |
progressbar |
Whether PyMC shows a progress bar |
random_seed |
Sampling reproducibility |
If you do not specify progressbar, Abacus defaults it to True unless your
sampler_config already sets it.
When to build first
For a standard workflow, call fit() directly.
Call build_model(X, y) first only when you need to inspect or modify the
graph before sampling. For example:
This pattern is also useful when you need to add events before fitting. Call
add_events(...) before build_model(...) or fit(...).
Inspect fitted results
After fitting, common entry points are:
mmm.idatammm.posteriormmm.modelmmm.plotmmm.summarymmm.diagnostics
Example:
Common pitfalls
- Leaving the target column inside
X - Passing pandas
Xandywith different indexes - Changing the model graph after fitting and expecting existing samples to stay valid
- Assuming constructor
sampler_configoverrides explicitfit()kwargs; it does not - Adding events after the model has already been built
Next steps
- Run Prior Predictive Checks before posterior sampling when you are tuning priors or model structure.
- Read Save and Load if you want to persist a fitted model.