BaseMMM#

class pymc_marketing.mmm.delayed_saturated_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=Union[str, Annotated[AdstockTransformation, InstanceOf]], required=True, description='Type of adstock transformation to apply.'), saturation=FieldInfo(annotation=Union[str, Annotated[SaturationTransformation, InstanceOf]], required=True, description='Type of saturation transformation to apply.'), adstock_max_lag=FieldInfo(annotation=Union[int, NoneType], required=False, default=None, description='Number of lags to consider in the adstock transformation. Defaults to the max lag of the adstock transformation.', metadata=[Gt(gt=0)]), 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.'))[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, ...])

Constructor method.

BaseMMM.attrs_to_init_kwargs(attrs)

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

Builds a probabilistic model using PyMC for marketing mix modeling.

BaseMMM.channel_contributions_forward_pass(...)

Evaluate the channel contribution for a given channel data and a fitted model, ie.

BaseMMM.compute_channel_contribution_original_scale()

Compute the channel contributions in the original scale of the target variable.

BaseMMM.compute_mean_contributions_over_time([...])

Get the contributions of each channel over time.

BaseMMM.create_idata_attrs()

BaseMMM.fit(X[, y, progressbar, ...])

Fit a model using the data passed as a parameter.

BaseMMM.forward_pass(x)

Transforms channel input into target contributions of each channel.

BaseMMM.get_errors([original_scale])

Get model errors posterior distribution.

BaseMMM.get_params([deep])

Get all the model parameters needed to instantiate a copy of the model, not including training data.

BaseMMM.get_target_transformer()

Return the target transformer pipeline used for preprocessing the target variable.

BaseMMM.graphviz(**kwargs)

BaseMMM.load(fname)

Creates a ModelBuilder instance from a file,

BaseMMM.plot_channel_contribution_share_hdi([...])

Plot the share of channel contributions in a forest plot.

BaseMMM.plot_components_contributions(...)

Plot the target variable and the posterior predictive model components in the scaled space.

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.

BaseMMM.plot_posterior_predictive([...])

Plot posterior distribution from the model fit.

BaseMMM.plot_prior_predictive(**plt_kwargs)

BaseMMM.plot_waterfall_components_decomposition([...])

This function creates a waterfall plot.

BaseMMM.predict(X_pred[, extend_idata])

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

BaseMMM.predict_posterior(X_pred[, ...])

Generate posterior predictive samples on unseen data.

BaseMMM.predict_proba(X_pred[, ...])

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_pred)

Sample from the model's posterior predictive distribution.

BaseMMM.sample_prior_predictive(X_pred[, ...])

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.set_params(**params)

Set all the model parameters needed to instantiate the model, not including training data.

BaseMMM.validate(target, data)

Validates the input data based on the specified target type.

BaseMMM.validate_channel_columns(data)

BaseMMM.validate_date_col(data)

BaseMMM.validate_target(data)

Attributes

X

default_model_config

Returns a class default config dict for model builder if no model_config is provided on class initialization Useful for understanding structure of required model_config to allow its customization by users

default_sampler_config

Returns a class default sampler dict for model builder if no sampler_config is provided on class initialization Useful for understanding structure of required sampler_config to allow its customization by users Examples -------- >>> @classmethod >>> def default_sampler_config(self): >>> Return { >>> 'draws': 1_000, >>> 'tune': 1_000, >>> 'chains': 1, >>> 'target_accept': 0.95, >>> }

fit_result

id

Generate a unique hash value for the model.

methods

output_var

Defines target variable for the model

posterior_predictive

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