DataDerivedScaling#

class pymc_marketing.mmm.scaling.DataDerivedScaling(**data)[source]#

Scale by a statistic of the data, computed at fit time.

Both reductions are signed: method="max" is data.max(...) and method="mean" is data.mean(...), not the maximum or mean of the absolute values. Unlike FixedScaling, which requires positive values, nothing constrains the sign or magnitude of a computed scale, so two cases are reachable and neither is reported:

  • A slice whose reduction is negative gives a scale that flips the sign of the scaled data. The round trip still closes, because original_scale_transform multiplies by the same scale again, but the flip is invisible.

  • A slice whose reduction is exactly zero gives a scale of zero, so every scaled value is NaN or infinite. MMM.build_model rewrites those to 0.0, which replaces that slice’s data with zeros rather than scaling it. Under a likelihood with positive support this raises at build time; under Normal it fits on the zeros silently.

An all-zero target reaches the second case, which is what sample_prior_predictive and fit produce when no y is given.

Parameters:
method"max" | "mean"

The scaling method. Signed, see above.

dimsstr or tuple of str

The dimensions to perform the operation through ("date" is always included implicitly).

Examples

Max scaling (default behaviour):

DataDerivedScaling(method="max", dims=())

Mean scaling across a custom dimension:

DataDerivedScaling(method="mean", dims=("country",))

Methods

DataDerivedScaling.__init__(**data)

Create a new model by parsing and validating input data from keyword arguments.

DataDerivedScaling.construct([_fields_set])

DataDerivedScaling.copy(*[, include, ...])

Returns a copy of the model.

DataDerivedScaling.dict(*[, include, ...])

DataDerivedScaling.from_dict(data)

Reconstruct from a dict via Pydantic model_validate.

DataDerivedScaling.from_orm(obj)

DataDerivedScaling.json(*[, include, ...])

DataDerivedScaling.model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

DataDerivedScaling.parse_file(path, *[, ...])

DataDerivedScaling.parse_obj(obj)

DataDerivedScaling.parse_raw(b, *[, ...])

DataDerivedScaling.scaling_description()

Human-readable summary of the scaling strategy.

DataDerivedScaling.schema([by_alias, ...])

DataDerivedScaling.schema_json(*[, ...])

DataDerivedScaling.to_dict([_orig])

Serialize to a dict via Pydantic model_dump.

DataDerivedScaling.update_forward_refs(**localns)

DataDerivedScaling.validate(value)

Attributes

DataDerivedScaling.model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

DataDerivedScaling.method

DataDerivedScaling.dims