add_cost_per_target_potentials#
- pymc_marketing.mmm.lift_test.add_cost_per_target_potentials(calibration_df, *, model=None, cpt_value, target_column='cost_per_target', name_prefix='cpt_calibration', get_indices=<function exact_row_indices>)[source]#
Add
pm.Potentialpenalties to calibrate cost-per-target.For each row, we compute the mean of
cpt_variable_nameacross 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. The DataFrame must also include one column per model dimension found in the CPT variable (excludingdate).- model
pm.Model, optional Model containing the cost-per-target tensor. If None, uses the current model context.
- cpt_value
TensorVariable Tensor representing cost-per-target values over the model coordinates.
- target_column
str Column in
calibration_dfcontaining the calibration targets.- 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
cpt_tensor = pt.as_tensor_variable( np.full((len(dates), len(geo), len(channels)), 30.0, dtype=float) ) 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_value=cpt_tensor, name_prefix="cpt_calibration", )