BaseMMM#
- class pymc_marketing.mmm.mmm.BaseMMM(date_column=FieldInfo(annotation=str, required=True, description='Column name of the date variable.'), channel_columns=FieldInfo(annotation=list[str], required=True, description='Column names of the media channel variables.', metadata=[MinLen(min_length=1)]), adstock=FieldInfo(annotation=AdstockTransformation, required=True, description='Type of adstock transformation to apply.', metadata=[InstanceOf()]), saturation=FieldInfo(annotation=SaturationTransformation, required=True, description='Type of saturation transformation to apply.', metadata=[InstanceOf()]), time_varying_intercept=FieldInfo(annotation=bool, required=False, default=False, description='Whether to consider time-varying intercept.'), time_varying_media=FieldInfo(annotation=bool, required=False, default=False, description='Whether to consider time-varying media contributions.'), model_config=FieldInfo(annotation=Union[dict, NoneType], required=False, default=None, description='Model configuration.'), sampler_config=FieldInfo(annotation=Union[dict, NoneType], required=False, default=None, description='Sampler configuration.'), validate_data=FieldInfo(annotation=bool, required=False, default=True, description='Whether to validate the data before fitting to model'), control_columns=None, yearly_seasonality=None, adstock_first=FieldInfo(annotation=bool, required=False, default=True, description='Whether to apply adstock first.'), dag=FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='Optional DAG provided as a string Dot format for causal identification.'), treatment_nodes=FieldInfo(annotation=Union[list[str], tuple[str], NoneType], required=False, default=None, description='Column names of the variables of interest to identify causal effects on outcome.'), outcome_node=FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='Name of the outcome variable.'))[source]#
Base class for a media mix model using Delayed Adstock and Logistic Saturation (see [1]).
References
[1]Jin, Yuxue, et al. “Bayesian methods for media mix modeling with carryover and shape effects.” (2017).
Methods
BaseMMM.__init__
([date_column, ...])Define the constructor method.
BaseMMM.attrs_to_init_kwargs
(attrs)Convert attributes to initialization kwargs.
BaseMMM.build_from_idata
(idata)Build model from the InferenceData object.
BaseMMM.build_model
(X, y, **kwargs)Build a probabilistic model using PyMC for marketing mix modeling.
Evaluate the channel contribution for a given channel data and a fitted model, ie.
BaseMMM.compute_channel_contribution_original_scale
([prior])Compute the channel contributions in the original scale of the target variable.
Get the contributions of each channel over time.
BaseMMM.create_fit_data
(X, y)Create the fit_data group based on the input data.
Create attributes for the inference data.
BaseMMM.fit
(X[, y, progressbar, random_seed])Fit a model using the data passed as a parameter.
Transform channel input into target contributions of each channel.
Get the share of channel contributions in the original scale of the target variable.
BaseMMM.get_errors
([original_scale])Get model errors posterior distribution.
Return the target transformer pipeline used for preprocessing the target variable.
BaseMMM.graphviz
(**kwargs)Get the graphviz representation of the model.
BaseMMM.load
(fname)Create a ModelBuilder instance from a file.
BaseMMM.load_from_idata
(idata)Create a ModelBuilder instance from an InferenceData object.
Plot the share of channel contributions in a forest plot.
Plot the target variable and the posterior predictive model components.
BaseMMM.plot_errors
([original_scale, ax])Plot model errors by taking the difference between true values and predicted.
BaseMMM.plot_grouped_contribution_breakdown_over_time
([...])Plot a time series area chart for all channel contributions.
Plot the posterior predictive distribution from the model fit.
Plot the prior predictive distribution from the model fit.
BaseMMM.plot_prior_vs_posterior
(var_name[, ...])Plot the prior vs posterior distribution for a specified variable in a 3 columngrid layout.
Create a waterfall plot.
Post-sample model transformation in order to store the HSGP state from fit.
BaseMMM.predict
([X, extend_idata])Use a model to predict on unseen data and return point prediction of all the samples.
BaseMMM.predict_posterior
([X, extend_idata, ...])Generate posterior predictive samples on unseen data.
BaseMMM.predict_proba
([X, extend_idata, ...])Alias for
predict_posterior
, for consistency with scikit-learn probabilistic estimators.BaseMMM.preprocess
(target, data)Preprocess the provided data according to the specified target.
BaseMMM.sample_posterior_predictive
([X, ...])Sample from the model's posterior predictive distribution.
BaseMMM.sample_prior_predictive
([X, y, ...])Sample from the model's prior predictive distribution.
BaseMMM.save
(fname)Save the model's inference data to a file.
BaseMMM.set_idata_attrs
([idata])Set attributes on an InferenceData object.
BaseMMM.validate
(target, data)Validate the input data based on the specified target type.
Validate the channel columns.
Validate the date column.
BaseMMM.validate_target
(data)Validate the target column.
Attributes
X
default_model_config
Define the default model configuration.
default_sampler_config
Default sampler configuration for the model.
fit_result
Get the posterior fit_result.
id
Generate a unique hash value for the model.
methods
Get all methods of the object.
output_var
Define target variable for the model.
posterior
posterior_predictive
predictions
preprocessing_methods
A property that provides preprocessing methods for features ("X") and the target variable ("y").
prior
prior_predictive
validation_methods
A property that provides validation methods for features ("X") and the target variable ("y").
version
y
model
date_column
channel_columns