MMMModelBuilder#

class pymc_marketing.mmm.base.MMMModelBuilder(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)]), 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.'))[source]#

Base class for Marketing Mix Models (MMM).

Methods

MMMModelBuilder.__init__([date_column, ...])

Initialize model configuration and sampler configuration for the model.

MMMModelBuilder.attrs_to_init_kwargs(attrs)

Convert the model configuration and sampler configuration from the attributes to keyword arguments.

MMMModelBuilder.build_from_idata(idata)

Build model from the InferenceData object.

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

Create an instance of pm.Model based on provided data and model_config.

MMMModelBuilder.compute_channel_contribution_original_scale([prior])

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

MMMModelBuilder.compute_mean_contributions_over_time([...])

Get the contributions of each channel over time.

MMMModelBuilder.create_fit_data(X, y)

Create the fit_data group based on the input data.

MMMModelBuilder.create_idata_attrs()

Create attributes for the inference data.

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

Fit a model using the data passed as a parameter.

MMMModelBuilder.get_channel_contributions_share_samples([prior])

Get the share of channel contributions in the original scale of the target variable.

MMMModelBuilder.get_errors([original_scale])

Get model errors posterior distribution.

MMMModelBuilder.get_target_transformer()

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

MMMModelBuilder.graphviz(**kwargs)

Get the graphviz representation of the model.

MMMModelBuilder.load(fname)

Create a ModelBuilder instance from a file.

MMMModelBuilder.load_from_idata(idata)

Create a ModelBuilder instance from an InferenceData object.

MMMModelBuilder.plot_channel_contribution_share_hdi([...])

Plot the share of channel contributions in a forest plot.

MMMModelBuilder.plot_components_contributions(...)

Plot the target variable and the posterior predictive model components.

MMMModelBuilder.plot_errors([original_scale, ax])

Plot model errors by taking the difference between true values and predicted.

MMMModelBuilder.plot_grouped_contribution_breakdown_over_time([...])

Plot a time series area chart for all channel contributions.

MMMModelBuilder.plot_posterior_predictive([...])

Plot the posterior predictive distribution from the model fit.

MMMModelBuilder.plot_prior_predictive([...])

Plot the prior predictive distribution from the model fit.

MMMModelBuilder.plot_prior_vs_posterior(var_name)

Plot the prior vs posterior distribution for a specified variable in a 3 columngrid layout.

MMMModelBuilder.plot_waterfall_components_decomposition([...])

Create a waterfall plot.

MMMModelBuilder.post_sample_model_transformation()

Perform transformation on the model after sampling.

MMMModelBuilder.predict([X, extend_idata])

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

MMMModelBuilder.predict_posterior([X, ...])

Generate posterior predictive samples on unseen data.

MMMModelBuilder.predict_proba([X, ...])

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

MMMModelBuilder.preprocess(target, data)

Preprocess the provided data according to the specified target.

MMMModelBuilder.sample_posterior_predictive([...])

Sample from the model's posterior predictive distribution.

MMMModelBuilder.sample_prior_predictive([X, ...])

Sample from the model's prior predictive distribution.

MMMModelBuilder.save(fname)

Save the model's inference data to a file.

MMMModelBuilder.set_idata_attrs([idata])

Set attributes on an InferenceData object.

MMMModelBuilder.validate(target, data)

Validate the input data based on the specified target type.

Attributes

X

default_model_config

Return a class default configuration dictionary.

default_sampler_config

Return a class default sampler configuration dictionary.

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

Returns the name of the output variable of 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