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=False, default='y', 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, dag=FieldInfo(annotation=NoneType, required=False, default=None, description='Optional DAG provided as a string Dot format for causal identification.'), treatment_nodes=FieldInfo(annotation=NoneType, required=False, default=None, description='Column names of the variables of interest to identify causal effects on outcome.'), outcome_node=FieldInfo(annotation=NoneType, required=False, default=None, description='Name of the outcome variable.'), cost_per_unit=FieldInfo(annotation=NoneType, required=False, default=None, description='Cost per unit conversion factors for non-spend channels. Wide-format DataFrame where rows are (date, *custom_dims) combinations and columns are channel names containing cost values. Not all model channels need to appear; missing channels default to 1.0 (already in spend units).'))[fuente]#

Clase del Modelo de Mezcla de Marketing para estimar el impacto de los canales de marketing en una variable objetivo.

Given a target variable \(y_{t}\) (e.g. sales or conversions), media variables \(x_{m, t}\) (e.g. impressions, clicks, or costs), and a set of control covariates \(z_{c, t}\) (e.g. holidays, pricing), we consider a Bayesian linear model of the form:

\[y_{t} = \alpha + \sum_{m=1}^{M}\beta_{m}\,f_{m}\!\bigl( \{x_{m,s}\}_{s \leq t}\bigr) + \sum_{c=1}^{C}\gamma_{c}\, z_{c, t} + \varepsilon_{t},\]

where \(\alpha\) is the intercept, \(f_{m}\) is a media transformation function that maps the history of channel \(m\) up to time \(t\) to a scalar contribution, capturing adstock (carry-over) and saturation effects, and \(\varepsilon_{t} \sim \mathcal{N}(0, \sigma^{2})\).

The model supports \(K \geq 0\) additional panel dimensions (e.g. geography, brand) specified via the dims parameter. When \(K > 0\), every variable — the target, media inputs, controls — and all parameters (\(\alpha\), \(\beta_{m}\), \(\gamma_{c}\), \(\sigma\), and the parameters of \(f_{m}\)) are implicitly indexed over the Cartesian product of those dimensions. For example, with dims=("geo",) each parameter is geo-specific — \(y_{t,g}\), \(\alpha_{g}\), \(\beta_{m,g}\), etc. — but they share hierarchical priors so that information is partially pooled across geographies. When dims=("geo", "brand"), every quantity is indexed by \((t, g, b)\). The equation above is written for a single slice of these dimensions; the full model is their product over all dimension combinations.

Atributos:
date_columnstr

El nombre de la columna que representa la fecha en el conjunto de datos.

channel_columnslist[str]

A list of column names representing the marketing channels.

target_columnstr, optional

The name of the column representing the target variable in the dataset. Defaults to "y".

adstock : TransformaciónAdstockTransformaciónAdstock

La transformación de adstock que se aplicará a los datos del canal.

saturación : SaturationTransformationTransformación de Saturación

La transformación de saturación que se aplicará a los datos del canal.

time_varying_interceptbool or HSGPBase

Whether to use a time-varying intercept in the model, or an HSGPBase instance specifying dims and priors.

time_varying_mediabool or HSGPBase

Whether to use time-varying effects for media channels, or an HSGPBase instance specifying dims and priors.

dimstuple[str, …] or None

Additional panel dimensions for the model (e.g. ("geo",)). One categorical column per dimension must be present in the dataset. Data must be rectangular across these dimensions (i.e. the same dates for every combination).

scalingScaling or dict or None

Scaling methods for the target variable and the marketing channels. Defaults to max-absolute scaling for both.

model_configdict or None

Configuration settings for the model priors and likelihood.

sampler_configdict or None

Configuración de los ajustes para el muestreador.

control_columnslist[str] or None

Column names of control covariates to include in the model.

yearly_seasonalityint or None

Number of Fourier modes for yearly seasonality.

adstock_first : boolbool

Whether to apply adstock before saturation (default True).

Notes

  1. Before fitting, the target variable and media channels are scaled (by default using max-absolute scaling). Control variables are not scaled automatically — apply your own preprocessing if needed.

  2. Yearly seasonality can be added as Fourier modes via the yearly_seasonality parameter.

  3. The model can be calibrated with:

For details on a vanilla implementation in PyMC see [2].

References

[1]

Jin, Yuxue, et al. «Bayesian methods for media mix modeling with carryover and shape effects.» (2017).

Métodos

MMM.__init__(*[, date_column, ...])

Defina el método constructor.

MMM.add_cost_per_target_calibration(datos, ...)

Calibrate cost-per-target using an observed Normal likelihood.

MMM.add_events(df_events, prefijo, efecto)

Agregue efectos de evento al modelo.

MMM.add_lift_test_measurements(df_lift_test)

Agregue pruebas de elevación al modelo.

MMM.add_original_scale_contribution_variable(var)

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

MMM.approximate_fit(X[, y, barra_de_progreso, ...])

Ajuste un modelo utilizando Inferencia Variacional y devuelva InferenceData.

MMM.attrs_to_init_kwargs(attrs)

Convierte los atributos idata a los kwargs de inicialización del modelo.

MMM.build_from_idata(idata)

Reconstruya el modelo a partir de un objeto InferenceData.

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

Construya un modelo probabilístico utilizando PyMC para el modelado de mezcla de marketing.

MMM.compute_mean_contributions_over_time()

Get the mean contribution of each component over time in original scale.

MMM.create_fit_data(X, y)

Cree un conjunto de datos adecuado alineado en fecha y dimensiones presentes.

MMM.create_idata_attrs()

Devuelva los atributos idata para el modelo.

MMM.fit(X[, y, barra_de_progreso, semilla_aleatoria])

Fit the model and inject cost_per_unit metadata if provided.

MMM.forward_pass(x, dims)

Transformar la entrada del canal en las contribuciones objetivo de cada canal.

MMM.get_scales_as_xarray()

Devuelva los factores de escalado guardados como DataArrays de xarray.

MMM.graphviz(**kwargs)

Obtenga la representación graphviz del modelo.

MMM.idata_to_init_kwargs(idata)

Cree la configuración del modelo y la configuración del muestreador a partir de InferenceData a argumentos de palabra clave.

MMM.load(fname[, check])

Cree una instancia de ModelBuilder a partir de un archivo.

MMM.load_from_idata(idata[, check])

Load from InferenceData, auto-migrating old formats.

MMM.post_sample_model_transformation()

Perform transformation on the model after sampling.

MMM.predict([X, extend_idata])

Utilice un modelo para predecir en datos no vistos y devuelva la predicción puntual de todas las muestras.

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

Generar muestras predictivas posteriores en datos no vistos.

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

Alias para predict_posterior, por consistencia con los estimadores probabilísticos de scikit-learn.

MMM.sample_adstock_curve([amount, ...])

Sample adstock curves from posterior parameters.

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

Muestra de la distribución predictiva posterior del modelo.

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

Muestra de la distribución predictiva previa del modelo.

MMM.sample_saturation_curve([max_value, ...])

Sample saturation curves from posterior parameters.

MMM.save(fname, **kwargs)

Save the model, including supplementary data for MuEffects.

MMM.set_cost_per_unit(cost_per_unit)

Set or update cost_per_unit metadata for the fitted model.

MMM.set_idata_attrs([idata])

Establecer atributos en un objeto InferenceData.

MMM.table(**model_table_kwargs)

Obtenga la tabla resumen del modelo.

Atributos

data

Get data wrapper for InferenceData access and manipulation.

default_model_config

Defina la configuración del modelo predeterminado.

default_sampler_config

Configuración de muestreador predeterminada.

fit_result

Obtenga el resultado de ajuste posterior fit_result.

frozen_deterministics

Deterministic variables that must be frozen at posterior values.

id

Generar un valor hash único para el modelo.

incrementality

Access incrementality and counterfactual analysis functionality.

output_var

plot

Utilice el MMMPlotSuite para graficar los resultados.

plot_interactive

Access interactive Plotly plotting functionality.

posterior

posterior_predictive

predictions

prior

prior_predictive

sensitivity

Acceda a la funcionalidad de análisis de sensibilidad.

summary

Access summary DataFrame generation functionality.

version

idata

sampler_config

model_config