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.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. The DataFrame must also include one column per model dimension found in the CPT variable (excluding date).

modelpm.Model, optional

Model containing the cost-per-target tensor. If None, uses the current model context.

cpt_valueTensorVariable

Tensor representing cost-per-target values over the model coordinates.

target_columnstr

Column in calibration_df containing the calibration targets.

name_prefixstr

Prefix for created potential names.

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

Alignment function mapping rows to model coordinate indices.

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