FrequencyReachAdditiveEffect#
- class pymc_marketing.mmm.additive_effect.frequency_reach_effect.FrequencyReachAdditiveEffect(**data)[source]#
Additive mu effect from frequency & reach observations.
Follows the Meridian-style reach-frequency modelling approach: saturation is applied to frequency only, reach enters linearly, and the product is passed through adstock before being scaled by a per-channel beta coefficient.
R&F channels live in a dedicated
rf_channelcoordinate and are fully independent of the standard MMMchannel_columns.- Parameters:
- df_frequency_reach
pd.DataFrame Long-format DataFrame with columns at least:
date,channel,frequency,reach. Additional columns matchingmmm.dims(e.g.geo) are optional and will be preserved.- saturation
HillShapeSaturation Shape-only Hill saturation applied to frequency. Must not contain an internal amplitude parameter to keep the model identifiable (that role is played by
beta).- adstock
AdstockTransformation Adstock kernel applied to the effective-exposure signal (
reach × saturated_frequency).- beta_prior
Prior, optional Prior for the per-channel scaling coefficient
beta. Defaults toHalfNormal(sigma=1), which enforces non-negative contributions (semantically appropriate for R&F channels). AnyPriorinstance is accepted; dims must not be set — they are assigned automatically to"rf_channel"at model build time.- cost_per_unit
pd.DataFrame, optional Cost per impression for each R&F channel, optionally varying by date. Wide-format DataFrame with a
datecolumn and one column per channel name matching those indf_frequency_reach. All values must be positive. Required when budget optimization is used.- assumed_frequency
floatordict[str,float], optional Fixed average-frequency assumption used during budget optimization to split total impressions into reach and frequency. A scalar applies to all channels; a dict maps channel names to per-channel values. When
None(default), the historical per-channel median frequency is used.- prefix
str, optional Variable-name prefix for all PyMC random and deterministic variables created by this effect. Defaults to
"frequency_reach".- date_column
str, optional Name of the date column in
df_frequency_reach. Defaults to"date".- channel_column
str, optional Name of the channel column in
df_frequency_reach. Defaults to"channel".
- df_frequency_reach
Notes
The PyMC coordinate for R&F channels is always
"rf_channel"regardless ofchannel_column. This ensures that R&F channel names cannot collide with standard media channel coordinates.Methods
Create a new model by parsing and validating input data from keyword arguments.
FrequencyReachAdditiveEffect.build_rf_optimization_tensors(...)Build (reach, frequency) PyTensor tensors for optimizer graph injection.
FrequencyReachAdditiveEffect.copy(*[, ...])Returns a copy of the model.
Register pm.Data nodes required for the effect.
Build the Meridian-style R&F pipeline and return the aggregate effect.
FrequencyReachAdditiveEffect.dict(*[, ...])Return a per-channel frequency array for use during optimization.
FrequencyReachAdditiveEffect.json(*[, ...])FrequencyReachAdditiveEffect.model_parametrized_name(params)Compute the class name for parametrizations of generic classes.
FrequencyReachAdditiveEffect.set_data(mmm, ...)Update reach & frequency data for prediction (e.g. future) dates.
Attributes
cost_per_unit_xarrayParse
cost_per_unitDataFrame into a DataArray.model_computed_fieldsmodel_configConfiguration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].model_extraGet extra fields set during validation.
model_fieldsmodel_fields_setReturns the set of fields that have been explicitly set on this model instance.
rf_channelsSorted list of R&F channel names from the DataFrame.
df_frequency_reachsaturationadstockbeta_priorcost_per_unitassumed_frequencyprefixdate_columnchannel_column