MMM#
- class pymc_marketing.mmm.multidimensional.MMM(date_column=FieldInfo(annotation=NoneType, required=True, description='Column name of the date variable.'), channel_columns=FieldInfo(annotation=NoneType, required=True, description='Column names of the media channel variables.', metadata=[MinLen(min_length=1)]), target_column=FieldInfo(annotation=NoneType, required=True, description='The name of the target column.'), adstock=FieldInfo(annotation=NoneType, required=True, description='Type of adstock transformation to apply.'), saturation=FieldInfo(annotation=NoneType, required=True, description='The saturation transformation to apply to the channel data.'), time_varying_intercept=False, time_varying_media=False, dims=FieldInfo(annotation=NoneType, required=False, default=None, description='Additional dimensions for the model.'), scaling=FieldInfo(annotation=NoneType, required=False, default=None, description='Scaling configuration for the model.'), model_config=FieldInfo(annotation=NoneType, required=False, default=None, description='Configuration settings for the model.'), sampler_config=FieldInfo(annotation=NoneType, required=False, default=None, description='Configuration settings for the sampler.'), 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_column
str
The name of the column representing the date in the dataset.
- channel_columns
list
[str
] A list of columns representing the marketing channels.
- target_column
str
The name of the column representing the target variable to be predicted.
- adstock
AdstockTransformation
The adstock transformation to apply to the channel data.
- saturation
SaturationTransformation
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.
- dims
tuple
|None
Additional dimensions for the model.
- scaling
Scaling
|dict
|None
Scaling methods to be used for the target variable and the marketing channels. Defaults to max scaling for both.
- model_config
dict
|None
Configuration settings for the model.
- sampler_config
dict
|None
Configuration settings for the sampler.
- control_columns
list
[str
] |None
A list of control variables to include in the model.
- yearly_seasonality
int
|None
The number of yearly seasonalities to include in the model.
- adstock_firstbool
Whether to apply adstock transformations before saturation.
- date_column
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_lift_test_measurements
(df_lift_test)Add lift tests to the model.
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.
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.
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.
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