validate_cost_per_target_rows#

pymc_marketing.mmm.lift_test.validate_cost_per_target_rows(calibration_df, model, *, target_column='cost_per_target', get_indices=<function exact_row_indices>, likelihood=None)[source]#

Check a cost-per-target table and likelihood against model without touching the graph.

Shared by add_cost_per_target_observations() and MMM.add_cost_per_target_calibration so that a table is refused by one set of checks, before either of them changes the model.

Parameters:
  • calibration_df (DataFrame) – One row per calibration value, with a channel column, one column per non-date dim of channel_data, target_column and sigma.

  • model (Model) – The model whose coordinates the rows are mapped to.

  • target_column (str) – Column holding the calibration values.

  • get_indices (Callable[[DataFrame, Model], dict[str, Sequence[int] | NDArray[integer]]]) – Maps the dim columns of calibration_df to model coordinate indices.

  • likelihood (Prior | None) – Calibration likelihood; None means Prior("Normal"). See add_cost_per_target_observations() for the supported families.

Return type:

tuple[Indices, np.ndarray, np.ndarray, Prior]

Returns:

The row indices per dim, the calibration values and their sigma as float arrays, and the resolved likelihood.

Raises:
  • TypeError – If likelihood is not a Prior.

  • KeyError – If a required column or dim column is missing.

  • UnalignedValuesError – If a channel or dim label is not a model coordinate (with the default get_indices).

  • ValueError – If likelihood sets any parameter other than StudentT’s nu, dims, a transform or centered=False, is a StudentT without nu or with a nu that carries dims or arrays, is a non-positive constant or a prior that can go negative, or is not Normal, StudentT or LogNormal; if target_column or sigma cannot be converted to finite float values; if sigma is not strictly positive; or if a calibration value is not strictly positive under LogNormal.