MMM.add_lift_test_measurements#
- MMM.add_lift_test_measurements(df_lift_test, dist=<class 'pymc.distributions.continuous.Gamma'>, name='lift_measurements')[source]#
Add lift tests to the model.
The model for the difference of a channel’s saturation curve is created from
x
andx + delta_x
for each channel. This random variable is then conditioned using the empirical lift,delta_y
, andsigma
of the lift test with the specified distributiondist
.The pseudo-code for the lift test is as follows:
model_estimated_lift = saturation_curve(x + delta_x) - saturation_curve(x) empirical_lift = delta_y dist(abs(model_estimated_lift), sigma=sigma, observed=abs(empirical_lift))
The model has to be built before adding the lift tests.
- Parameters:
- df_lift_test
pd.DataFrame
- DataFrame with lift test results with at least the following columns:
DIM_NAME
: dimension name. One column per dimension inmmm.dims
.channel
: channel name. Must be present inchannel_columns
.x
: x axis value of the lift test.delta_x
: change in x axis value of the lift test.delta_y
: change in y axis value of the lift test.sigma
: standard deviation of the lift test.
- dist
pm.Distribution
, optional The distribution to use for the likelihood, by default pm.Gamma
- name
str
, optional The name of the likelihood of the lift test contribution(s), by default “lift_measurements”. Name change required if calling this method multiple times.
- df_lift_test
- Raises:
RuntimeError
If the model has not been built yet.
KeyError
If the ‘channel’ column or any of the model dimensions is not present in df_lift_test.
Examples
Build the model first then add lift test measurements.
import pandas as pd import numpy as np from pymc_marketing.mmm import GeometricAdstock, LogisticSaturation from pymc_marketing.mmm.multidimensional import MMM model = MMM( date_column="date", channel_columns=["x1", "x2"], target_column="target", adstock=GeometricAdstock(l_max=8), saturation=LogisticSaturation(), yearly_seasonality=2, dims=("geo",), ) X = pd.DataFrame( { "date": np.tile( pd.date_range(start="2025-01-01", end="2025-05-01", freq="W"), 2 ), "x1": np.random.rand(34), "x2": np.random.rand(34), "target": np.random.rand(34), "geo": 17 * ["FIN"] + 17 * ["SWE"], } ) y = X["target"] model.build_model(X.drop(columns=["target"]), y) df_lift_test = pd.DataFrame( { "channel": ["x1", "x1"], "geo": ["FIN", "SWE"], "x": [1, 1], "delta_x": [0.1, 0.2], "delta_y": [0.1, 0.1], "sigma": [0.1, 0.1], } ) model.add_lift_test_measurements(df_lift_test)