add_cost_per_target_potentials#
- pymc_marketing.mmm.lift_test.add_cost_per_target_potentials(calibration_df, *, model=None, cpt_variable_name='cost_per_target', name_prefix='cpt_calibration', get_indices=<function exact_row_indices>)[source]#
Add
pm.Potential
penalties to calibrate cost-per-target.For each row, we compute the mean of
cpt_variable_name
across the date dimension for the specified (dims, channel) slice and add a soft quadratic penalty:penalty = - |cpt_mean - target|^2 / (2 * sigma^2)
.- Parameters:
- calibration_df
pd.DataFrame
Must include columns
channel
,sigma
, and a target column. By default the target column is assumed to becost_per_target
; if a column matchingcpt_variable_name
is present it will be used instead. The DataFrame must also include one column per model dimension found in the CPT variable (excludingdate
).- model
pm.Model
, optional Model containing the
cpt_variable_name
Deterministic with dims (“date”, *dims, “channel”). If None, uses the current model context.- cpt_variable_name
str
Name of the cost-per-target Deterministic variable.
- name_prefix
str
Prefix for created potential names.
- get_indices
Callable
[[pd.DataFrame
,pm.Model
],Indices
] Alignment function mapping rows to model coordinate indices.
- calibration_df
Examples
calibration_df = pd.DataFrame( { "channel": ["C1", "C2"], "geo": ["US", "US"], # add dims as needed "cost_per_target": [30.0, 45.0], "sigma": [2.0, 3.0], } ) add_cost_per_target_potentials( calibration_df=calibration_df, model=mmm.model, cpt_variable_name="cost_per_target", name_prefix="cpt_calibration", )