exact_row_indices#
- pymc_marketing.mmm.lift_test.exact_row_indices(df, model)[source]#
Get indices in the model for each row in the DataFrame.
Assumes any column in the DataFrame is a coordinate in the model with the same name.
If the DataFrame has columns that are not in the model, it will raise an error.
- Parameters:
- df
pd.DataFrame DataFrame with coordinates combinations.
- model
pm.Model PyMC model with all the coordinates in the DataFrame.
- df
- Returns:
dict[str,np.ndarray]Dictionary of indices for the lift test results in the model.
- Raises:
UnalignedValuesErrorIf some values are not aligned. This means that some values in the DataFrame are not in the model.
KeyErrorIf some coordinates in the DataFrame are not in the model.
Examples
Get the indices from a DataFrame and model:
import pymc as pm import pandas as pd from pymc_marketing.mmm.lift_test import exact_row_indices df_lift_test = pd.DataFrame( { "channel": [0, 1, 0], "geo": ["A", "B", "B"], } ) coords = {"channel": [0, 1, 2], "geo": ["A", "B", "C"]} model = pm.Model(coords=coords) indices = exact_row_indices(df_lift_test, model) # {'channel': array([0, 1, 0]), 'geo': array([0, 1, 1])}