View source on GitHub
|
Builder for collecting incrementality experiment results and building ROI prior distributions.
meridian.model.calibration.prior_builder.CalibrationBuilder(
data: input_data.InputData,
*,
custom_prior: _PriorDistribution = None,
baseline_prior: _PriorDistribution = None,
adstock_decay_spec: _AdstockDecaySpec = constants.GEOMETRIC_DECAY,
alpha: _Alpha = calibration_constants.DEFAULT_ALPHA,
max_lag: int = constants.DEFAULT_MAX_LAG,
registry: (base.CalibrationRegistry | None) = None
) -> None
This builder collects incrementality experiment results for media and reach &
frequency channels, calibrates them, and outputs ROI priors for media and
reach & frequency channels as base.CalibratedDistribution objects.
Args | |
|---|---|
data
|
meridian.data.input_data.InputData object with Meridian dataset.
|
custom_prior
|
Mapping of channel name to ROI prior distribution for media
and reach & frequency channels that aren't undergoing calibration, or a
single custom prior for all uncalibrated channels. Entries are ignored
if the channel's prior is calibrated using experiment results via
CalibrationBuilder. Channels that aren't calibrated using
CalibrationBuilder and aren't included in this Mapping use the default
ROI prior of LogNormal(0.2, 0.9). Default is None.
|
baseline_prior
|
Mapping of channel name to baseline prior distribution, or a single baseline prior for all calibrated channels. If provided, the baseline prior will regularize the incrementality experiment results. Default is None. If None, an improper uniform distribution over the positive real numbers is used. |
adstock_decay_spec
|
Adstock decay specification used in duration
adjustments. This can be either 'geometric' or 'binomial', or a
mapping from channel name to the decay function string. Default is
'geometric'. This value should be consistent with the adstock decay
spec defined in the Meridian model's ModelSpec object. Entries for
organic media and organic reach & frequency channels are filtered out.
|
alpha
|
The decay rate parameter (between 0 and 1 inclusive) used for
duration adjustments. It determines the proportion of the total media
effect captured during the experiment window. This can be either a float
or a mapping from channel name to float. This value should be the same
as the point estimate of the alpha prior for each corresponding media
and reach & frequency channel. Default is 0.5.
|
max_lag
|
Maximum lag value used in duration adjustments. This value should
be consistent with the Meridian model's max_lag value set in the
ModelSpec object. Default is 8.
|
registry
|
The CalibrationRegistry to use. Primarily for testing. Default
is a new CalibrationRegistry instance.
|
Methods
build
build() -> base.CalibratedPriors
Builds ROI prior distributions for media and reach & frequency channels.
Transforms incrementality experiment estimates into calibrated priors and returns ROI prior distribution objects for media and reach & frequency channels.
| Returns | |
|---|---|
A base.CalibratedPriors object containing the calibrated prior
distributions corresponding to ROI priors for media and reach &
frequency channels.
|
with_incrementality_experiment_result
with_incrementality_experiment_result(
channel_name: str,
*,
point_estimates: _Floats,
standard_errors: _Floats,
experiment_kpi_types: _KpiTypes,
experiment_total_spends: _Floats,
experiment_start_dates: _Dates,
experiment_end_dates: _Dates,
point_estimate_adjustments: _OptionalFloats = None,
standard_error_adjustments: _OptionalFloats = None
) -> CalibrationBuilder
Adds one or more incrementality experiment results for the specified channel.
Calibration is supported for both revenue and non-revenue (such as
conversions)-based incrementality experiments. However, calibration is only
possible when the Meridian incremental outcome is in terms of revenue.
Non-revenue incrementality experiment results are translated to the unitless
Meridian ROI scale by using the revenue_per_kpi information available in
Meridian (meridian.data.input_data.InputData). The experiment_kpi_types
argument defines which experiments are of revenue and non-revenue type for
translation.
If revenue_per_kpi information is not available in Meridian,
translation of non-revenue experiments is not supported. In this
case, an error is raised.
| Args | |
|---|---|
channel_name
|
Name of the channel corresponding to the incrementality experiment result. |
point_estimates
|
A float or sequence of floats representing ROI or IKPC point estimates of the incrementality experiment results. |
standard_errors
|
A float or sequence of floats representing the standard error of the incrementality experiment point estimates. |
experiment_kpi_types
|
A string or sequence of strings denoting whether the
KPI of each experiment is of a 'revenue' or 'non-revenue' type.
|
experiment_total_spends
|
A float or sequence of floats representing the typical total spend for the experiment duration for the channel. Used to apply spend adjustments when converting the associated experiment to the ROI prior. |
experiment_start_dates
|
A datetime.date, datetime.datetime,
np.datetime64, string in 'YYYY-MM-DD' format, or sequences thereof
representing the start date of the experiment. Used to apply recency and
duration adjustments when converting the associated experiment to the
ROI prior.
|
experiment_end_dates
|
A datetime.date, datetime.datetime,
np.datetime64, string in 'YYYY-MM-DD' format, or sequences thereof
representing the end date of the experiment. Used to apply recency and
duration adjustments when converting the associated experiment to the
ROI prior.
|
point_estimate_adjustments
|
A float (or sequence of floats for multiple experiments) representing an optional point estimate adjustment which is added to the computed point estimate adjustment for each corresponding experiment. |
standard_error_adjustments
|
A float (or sequence of floats for multiple experiments) representing an optional standard error adjustment which is added to the computed standard error adjustment for each corresponding experiment. |
| Returns | |
|---|---|
The CalibrationBuilder instance.
|
| Raises | |
|---|---|
TypeError
|
If any of the required float arguments cannot be coerced due to invalid types. |
ValueError
|
If any of the following are true:
- Any of the start or end dates are None or cannot be parsed or coerced
to a datetime.date.
- Any standard_errors are non-positive.
- Any experiment_total_spends are not positive.
- The sequence arguments have mismatched lengths.
- The experiment start and end dates are not chronological.
- The channel name is not found in the model's paid channels.
- The experiment kpi_types are not compatible with the channel's KPI
type or are not supported.
- An experiment has statistically significantly negative lift.
- An experiment's spend exceeds the channel's total spend.
|
with_meridian_geox_experiment_result
with_meridian_geox_experiment_result(
channel_name: str,
geox_results: _GeoXResults,
experiment_kpi_types: _KpiTypes,
*,
point_estimate_adjustments: _OptionalFloats = None,
standard_error_adjustments: _OptionalFloats = None
) -> CalibrationBuilder
Adds one or more Meridian GeoX experiment results to the specified channel.
Extracts Meridian GeoX experiment information from one or more
meridian_geox.api.AnalysisResult objects for translation into
ROI priors.
Calibration is supported for both revenue and non-revenue(such as
conversions)-based incrementality experiments. However, calibration is only
possible when the Meridian incremental outcome is in terms of revenue.
Non-revenue incrementality experiment results are translated to the unitless
Meridian ROI scale by using the revenue_per_kpi information available in
Meridian(meridian.data.input_data.InputData). The experiment_kpi_types
argument defines which experiments are of revenue and non-revenue type for
translation.
If revenue_per_kpi information is not available in Meridian,
translation of non-revenue experiments is not supported. In this
case, an error is raised.
| Args | |
|---|---|
channel_name
|
Name of the channel corresponding to geox_results.
|
geox_results
|
A single or sequence of meridian_geox.api.AnalysisResult
objects containing experiment-derived KPI estimates and metadata.
|
experiment_kpi_types
|
A string or sequence of strings denoting whether the
KPI of each experiment is of a 'revenue' or 'non-revenue' type.
|
point_estimate_adjustments
|
A float (or sequence of floats for multiple experiments) representing an optional point estimate adjustment which is added to the computed point estimate adjustment for each corresponding experiment. |
standard_error_adjustments
|
A float (or sequence of floats for multiple experiments) representing an optional standard error adjustment which is added to the computed standard error adjustment for each corresponding experiment. |
| Returns | |
|---|---|
The CalibrationBuilder instance.
|
| Raises | |
|---|---|
ImportError
|
If the 'meridian_geox' library is not installed. |
ValueError
|
If any of the following are true:
- The channel name is not found in the model's paid channels.
- The sequence arguments have mismatched lengths.
- The experiment kpi_types are not compatible with the channel's KPI
type or are not supported.
- An experiment has kpi_type set to 'non-revenue' but
revenue_per_kpi is None.
- An experiment result is statistically significantly negative.
- An experiment result has a non-positive standard error.
|
InvalidGeoXResultError
|
If any of the GeoX results are invalid or incompatible with calibration. |
View source on GitHub