FixedScaling#

class pymc_marketing.mmm.scaling.FixedScaling(*, dims, value)[source]#

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

Parameters:
  • dims (str | tuple[str, ...]) – The dimensions to perform the operation through ("date" is always included implicitly).

  • value (float | dict[str, float] | 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.

    A DataArray is matched to the model’s coordinates by label, so the order of its labels and dimensions does not matter. Each of its dimensions must carry coordinate labels, and every model label must be present on it; dimensions without coordinates, missing labels, and duplicate labels raise a ValueError. Unlike the dict form, labels the model does not have are ignored, so one scale table can serve models fitted on different subsets of its labels.

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

FixedScaling.method

Return the scaling method name.

FixedScaling.model_config

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

FixedScaling.value

FixedScaling.dims