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_dfpd.DataFrame

Must include columns channel, sigma, and a target column. By default the target column is assumed to be cost_per_target; if a column matching cpt_variable_name is present it will be used instead. The DataFrame must also include one column per model dimension found in the CPT variable (excluding date).

modelpm.Model, optional

Model containing the cpt_variable_name Deterministic with dims (“date”, *dims, “channel”). If None, uses the current model context.

cpt_variable_namestr

Name of the cost-per-target Deterministic variable.

name_prefixstr

Prefix for created potential names.

get_indicesCallable[[pd.DataFrame, pm.Model], Indices]

Alignment function mapping rows to model coordinate indices.

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",
)