MMM.add_cost_per_target_calibration#

MMM.add_cost_per_target_calibration(data, calibration_data, name_prefix='cpt_calibration')[source]#

Calibrate cost-per-target using an observed Normal likelihood.

This computes cost-per-target as mean(spend) / mean(contribution) over the date dimension and adds an observed Normal likelihood for each calibration row:

Normal(mu=cpt_mean, sigma=sigma, observed=target)

Parameters:
datapd.DataFrame

Feature-like DataFrame with columns matching training X but with channel values representing spend (original units). Must include the same date and any model dims columns.

calibration_datapd.DataFrame

DataFrame with rows specifying calibration targets. Must include:

  • channel: channel name in self.channel_columns

  • cost_per_target: desired CPT value

  • sigma: accepted deviation; larger => weaker penalty

and one column per dimension in self.dims.

cpt_variable_namestr

Name for the cost-per-target Deterministic in the model.

name_prefixstr

Prefix to use for generated potential names.

Examples

Build a model and calibrate CPT for selected (dims, channel):

# spend data in original scale with the same structure as X
spend_df = X.copy()
# e.g., if X contains impressions, replace with monetary spend
# spend_df[channels] = ...

calibration_df = pd.DataFrame(
    {
        "channel": ["C1", "C2"],
        "geo": ["US", "US"],  # dims columns as needed
        "cost_per_target": [30.0, 45.0],
        "sigma": [2.0, 3.0],
    }
)

mmm.add_cost_per_target_calibration(
    data=spend_df,
    calibration_data=calibration_df,
    name_prefix="cpt_calibration",
)