MMM#

class pymc_marketing.mmm.multidimensional.MMM(date_column, channel_columns, target_column, adstock, saturation, time_varying_intercept=False, time_varying_media=False, dims=None, scaling=None, model_config=None, sampler_config=None, control_columns=None, yearly_seasonality=None, adstock_first=True)[source]#

Marketing Mix Model class for estimating the impact of marketing channels on a target variable.

This class implements the core functionality of a Marketing Mix Model (MMM), allowing for the specification of various marketing channels, adstock transformations, saturation effects, and time-varying parameters. It provides methods for fitting the model to data, making predictions, and visualizing the results.

Attributes:
date_columnstr

The name of the column representing the date in the dataset.

channel_columnslist[str]

A list of columns representing the marketing channels.

target_columnstr

The name of the column representing the target variable to be predicted.

adstockAdstockTransformation

The adstock transformation to apply to the channel data.

saturationSaturationTransformation

The saturation transformation to apply to the channel data.

time_varying_interceptbool

Whether to use a time-varying intercept in the model.

time_varying_mediabool

Whether to use time-varying effects for media channels.

dimstuple | None

Additional dimensions for the model.

model_configdict | None

Configuration settings for the model.

sampler_configdict | None

Configuration settings for the sampler.

control_columnslist[str] | None

A list of control variables to include in the model.

yearly_seasonalityint | None

The number of yearly seasonalities to include in the model.

adstock_firstbool

Whether to apply adstock transformations before saturation.

Methods

MMM.__init__(date_column, channel_columns, ...)

Define the constructor method.

MMM.add_events(df_events, prefix, effect)

Add event effects to the model.

MMM.add_original_scale_contribution_variable(var)

Add a pm.Deterministic variable to the model that multiplies by the scaler.

MMM.attrs_to_init_kwargs(attrs)

Convert the idata attributes to the model initialization kwargs.

MMM.build_from_idata(idata)

Build model from the InferenceData object.

MMM.build_model(X, y, **kwargs)

Build a probabilistic model using PyMC for marketing mix modeling.

MMM.create_fit_data(X, y)

Create the fit_data group based on the input data.

MMM.create_idata_attrs()

Return the idata attributes for the model.

MMM.fit(X[, y, progressbar, random_seed])

Fit a model using the data passed as a parameter.

MMM.forward_pass(x, dims)

Transform channel input into target contributions of each channel.

MMM.get_scales_as_xarray()

Return the saved scaling factors as xarray DataArrays.

MMM.graphviz(**kwargs)

Get the graphviz representation of the model.

MMM.load(fname)

Create a ModelBuilder instance from a file.

MMM.load_from_idata(idata)

Create a ModelBuilder instance from an InferenceData object.

MMM.post_sample_model_transformation()

Post-sample model transformation in order to store the HSGP state from fit.

MMM.predict([X, extend_idata])

Use a model to predict on unseen data and return point prediction of all the samples.

MMM.predict_posterior([X, extend_idata, ...])

Generate posterior predictive samples on unseen data.

MMM.predict_proba([X, extend_idata, combined])

Alias for predict_posterior, for consistency with scikit-learn probabilistic estimators.

MMM.sample_posterior_predictive([X, ...])

Sample from the model's posterior predictive distribution.

MMM.sample_prior_predictive([X, y, samples, ...])

Sample from the model's prior predictive distribution.

MMM.save(fname)

Save the model's inference data to a file.

MMM.set_idata_attrs([idata])

Set attributes on an InferenceData object.

Attributes

X

default_model_config

Define the default model configuration.

default_sampler_config

Default sampler configuration.

fit_result

Get the posterior fit_result.

id

Generate a unique hash value for the model.

output_var

Define target variable for the model.

plot

Use the MMMPlotSuite to plot the results.

posterior

posterior_predictive

predictions

prior

prior_predictive

version

y