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
floatapplies uniformly.A
dictmaps coordinate labels along the single remaining dimension after reducing overdateanddims(see the multidimensional MMM). If more than one non-reduced dimension remains, use anxarray.DataArraywhose dimensions broadcast to that grid (e.g. a vector overcountrywhen the media grid iscountry×channel). All values must be positive; NaNs are not allowed.A
DataArrayis 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 aValueError. Unlike thedictform, 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.DataArrayvalues.FixedScaling.from_long_dataframe(dims, df, ...)Build fixed scaling from a long table (one row per coordinate combination).
FixedScaling.json(*[, include, exclude, ...])Compute the class name for parametrizations of generic classes.
FixedScaling.parse_file(path, *[, ...])FixedScaling.parse_raw(b, *[, content_type, ...])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
Return the scaling method name.
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].