Quickstart: Python API
This page shows the fastest direct path from a pandas dataset to a fitted
PanelMMM.
If you have not prepared your dataset yet, read Data Preparation first.
Load a dataset
The repository includes bundled demo datasets under data/demo/. The
timeseries bundle is the simplest starting point because it has no extra panel
dimensions.
Construct PanelMMM
This example uses a plain timeseries. If your dataset has panel dimensions such
as geo or brand, add them with dims=(...) and keep those columns in X.
Fit the model
You can call fit() directly. If the model graph has not been built yet,
Abacus builds it for you.
fit() returns an arviz.InferenceData object and also stores it on the model
instance as mmm.idata.
Prior and posterior predictive checks
You can sample prior predictive draws before fitting:
After fitting, you can sample posterior predictive draws:
By default, this also stores posterior predictive draws on mmm.idata.
When to call build_model()
Call build_model(X, y) explicitly when you want to inspect or modify the PyMC
graph before sampling.
For example, you might build first so that you can add stored original-scale deterministics:
After that, fit the already-built model:
Basic outputs
After fitting, common next steps are:
You can also inspect:
mmm.posteriormmm.posterior_predictivemmm.summarymmm.diagnostics
Next steps
- Read Quickstart: YAML Builder if you want to move model configuration into YAML.
- Read Model Fitting for fitting, save/load, and predictive-check workflows in more detail.