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
dimsparameter. 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, withdims=("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. Whendims=("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_column
str El nombre de la columna que representa la fecha en el conjunto de datos.
- channel_columns
list[str] A list of column names representing the marketing channels.
- target_column
str, 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
HSGPBaseinstance specifying dims and priors.- time_varying_mediabool or
HSGPBase Whether to use time-varying effects for media channels, or an
HSGPBaseinstance specifying dims and priors.- dims
tuple[str, …] orNone 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).- scaling
ScalingordictorNone Scaling methods for the target variable and the marketing channels. Defaults to max-absolute scaling for both.
- model_config
dictorNone Configuration settings for the model priors and likelihood.
- sampler_config
dictorNone Configuración de los ajustes para el muestreador.
- control_columns
list[str] orNone Column names of control covariates to include in the model.
- yearly_seasonality
intorNone Number of Fourier modes for yearly seasonality.
- adstock_first : boolbool
Whether to apply adstock before saturation (default
True).
- date_column
Notes
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.
Yearly seasonality can be added as Fourier modes via the
yearly_seasonalityparameter.The model can be calibrated with:
Custom priors for any parameter via
model_config.Lift-test measurements added through
add_lift_test_measurements().
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.
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.
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.
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.
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.
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
dataGet data wrapper for InferenceData access and manipulation.
default_model_configDefina la configuración del modelo predeterminado.
default_sampler_configConfiguración de muestreador predeterminada.
fit_resultObtenga el resultado de ajuste posterior fit_result.
frozen_deterministicsDeterministic variables that must be frozen at posterior values.
idGenerar un valor hash único para el modelo.
incrementalityAccess incrementality and counterfactual analysis functionality.
output_varplotUtilice el MMMPlotSuite para graficar los resultados.
plot_interactiveAccess interactive Plotly plotting functionality.
posteriorposterior_predictivepredictionspriorprior_predictivesensitivityAcceda a la funcionalidad de análisis de sensibilidad.
summaryAccess summary DataFrame generation functionality.
versionidatasampler_configmodel_config