to_mmm_dataset#

pymc_marketing.mmm.data_conversion.to_mmm_dataset(X, y=None, *, date_column, dims=(), channel_columns, control_columns=None, extra_vars=None, target_column=None)[source]#

Normalise X (and optionally y) to a single canonical xr.Dataset.

This is the sole entry point for data normalisation in the MMM pipeline. It handles all supported input type combinations and returns a dataset with the canonical underscore-prefixed variable names (_channel, _target, _control).

Parameters:
X

Feature data.

y

Target variable. When X is already an xr.Dataset that contains a target / _target data variable this may be omitted.

date_column

Name of the date column in a pd.DataFrame input.

dims

Extra dimension names (e.g. ("geo",)).

channel_columns

Names of the media-channel columns.

control_columns

Names of control-variable columns.

extra_vars

Column names to carry as additional data variables (for custom DataVarMuEffect effects). Each becomes a variable indexed by date and any panel dims.

target_column

Name of the target column in a pd.DataFrame when y is omitted. Ignored when y is supplied or when X already carries a target variable.

Returns:
xr.Dataset

Dataset with variables _channel, (optional) _target, (optional) _control, any extra_vars, and coordinates for each dimension.