pymc-labs / pymc-marketing

Bayesian marketing toolbox in PyMC. Media Mix (MMM), customer lifetime value (CLV), buy-till-you-die (BTYD) models and more.
https://www.pymc-marketing.io/
Apache License 2.0
696 stars 194 forks source link

Time-Varying Media Visualization #765

Open wd60622 opened 4 months ago

wd60622 commented 4 months ago

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 time-varying-saturation-tanh

Another API might be pick out certain dates to visualize the saturation / contributions:

mmm.plot_time_varying_saturation(dates=["2023-01-01", "2023-06-01", "2023-12-01"])
AlfredoJF commented 2 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?

wd60622 commented 2 months ago

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):

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.

AlfredoJF commented 2 months ago

Amazing! Thanks @wd60622 I'll give it a try and let you know how it goes

wd60622 commented 2 months ago

Amazing! Thanks @wd60622 I'll give it a try and let you know how it goes

Sounds good. Let me know