-
Notifications
You must be signed in to change notification settings - Fork 309
Description
Hi there,
I have been experimenting with the new Multidimensional MMM class recently, and I am kind of new to PyMC-Marketing and PyMC. In my model, I have left a test set for model validation. So while I am able to get the out-of-sample prediction for the test set, I was wondering how could I also get the component contributions (channel contribution, channel contributions etc.) for the out of sample test set.
For example, I used this piece of code to get the prediction for the out-of-sample dataset:
y_pred_test = mmm.sample_posterior_predictive(
X_test,
include_last_observations=True,
extend_idata=False,
progressbar=False,
random_seed=rng,
)
and then something like this:
brand_dfs_oos = {}
for brand in mmm.model.coords["brand"]:
# Step 1: Select the brand's predicted y values
y_brand = y_pred_test["y"].sel(brand=brand)
# Step 2: Multiply by the scale for that brand
y_scaled = y_brand * scalers["target_scale"].sel(brand=brand)
# Step 3: Convert MultiIndex sample to separate dims (optional but cleaner)
y_scaled = y_scaled.unstack("sample") # gives dims: chain, draw, date
# Step 4: Mean over chain and draw (i.e., all posterior samples)
y_mean_per_date = y_scaled.mean(dim=["chain", "draw"])
ymd = y_mean_per_date.to_dataframe(name="predicted_brn").reset_index()
brand_dfs_oos[brand] = ymd
Here brand is equivalent to geo. But how do I compute the channel and control contribution in original scale. I do have the spend data for this out of sample period, it was just not used in the training.
Would appreciate any help.
Thanks!