FixedScaling#

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

Use a user-supplied constant that stays the same across model refreshes.

Parameters:
dimsstr or tuple of str

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

valuefloat or dict[str, float] or xarray.DataArray

Fixed scaling constant(s). A single float applies uniformly.

A dict maps coordinate labels along the single remaining dimension after reducing over date and dims (see the multidimensional MMM). If more than one non-reduced dimension remains, use an xarray.DataArray whose dimensions broadcast to that grid (e.g. a vector over country when the media grid is country × channel). All values must be positive; NaNs are not allowed.

Examples

Fixed scalar scaling for production stability:

FixedScaling(dims=(), value=10_000.0)

Per-dimension fixed scaling (multidimensional MMM):

FixedScaling(
    dims=("country",),
    value={"US": 50_000, "UK": 30_000},
)

Multi-dimensional fixed scale (e.g. country × channel) with xarray:

import xarray as xr

FixedScaling(
    dims=(),
    value=xr.DataArray(
        [[1e3, 2e3], [3e3, 4e3]],
        dims=("country", "channel"),
        coords={"country": ["US", "UK"], "channel": ["tv", "search"]},
    ),
)

Long-format table via from_long_dataframe():

FixedScaling.from_long_dataframe(
    dims=(),
    df=long_df,
    value_col="scale",
    dim_cols=["country", "channel"],
)

Methods

FixedScaling.__init__(**data)

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

FixedScaling.construct([_fields_set])

FixedScaling.copy(*[, include, exclude, ...])

Returns a copy of the model.

FixedScaling.dict(*[, include, exclude, ...])

FixedScaling.from_dict(data)

Deserialize; restores encoded xarray.DataArray values.

FixedScaling.from_long_dataframe(dims, df, ...)

Build fixed scaling from a long table (one row per coordinate combination).

FixedScaling.from_orm(obj)

FixedScaling.json(*[, include, exclude, ...])

FixedScaling.model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

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

FixedScaling.parse_obj(obj)

FixedScaling.parse_raw(b, *[, content_type, ...])

FixedScaling.scaling_description()

Human-readable summary of the scaling strategy.

FixedScaling.schema([by_alias, ref_template])

FixedScaling.schema_json(*[, by_alias, ...])

FixedScaling.to_dict([_orig])

Serialize to a dict via Pydantic model_dump.

FixedScaling.update_forward_refs(**localns)

FixedScaling.validate(value)

Attributes

method

Return the scaling method name.

model_computed_fields

model_config

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

model_extra

Get extra fields set during validation.

model_fields

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

value

dims