Open wd60622 opened 4 months ago
Hey @wd60622 is this issue related? https://github.com/pymc-labs/pymc-marketing/issues/819 ?
How can I get the saturation curves by date range?
Hi @AlfredoJF, that is not directly saved in the model, but I have some ideas.
The saturation curves can be generated with the SaturationTransformation
workflow:
saturation = mmm.saturation
# (chain, draw, spend, channel)
posterior_curve = saturation.sample_curve(mmm.idata.posterior)
In the case of the time-varying media, there are a few artifacts saved off (in the posterior via deterministics):
baseline_channel_contributions
: The baseline contribution at a given date (not saturation curve)media_temporal_latent_multiplier
: (chain, draw, date) multiplier for the saturation curvechannel_contributions
: (chain, draw, date, channel) contributions that are product of the previous two (not saturation curve)I think the media_temporal_latent_multiplier
would be of interest to you. You can subset to the dates you want then multiply with the saturation curve using xarray broadcasting.
my_dates = slice("2023-01-01", "2023-06-01")
# (chain, draw, spend, channel) * (chain, draw, date)
time_varying_curves = posterior_curve * mmm.idata.posterior["media_temporal_latent_multiplier"].sel(date=my_dates)
Give that a try and let me know if it gets you closer to what you are looking for.
Amazing! Thanks @wd60622 I'll give it a try and let you know how it goes
Amazing! Thanks @wd60622 I'll give it a try and let you know how it goes
Sounds good. Let me know
Following the addition of the time-varying media factor, a visualization to come with it would be helpful
Have something like this in mind, but really could be anything
Another API might be pick out certain dates to visualize the saturation / contributions: