Hierarchical MMM model for different geo using PyMC

I am trying to built an Hierarchical MMM model for different geo using PyMC. I am able to build an hierarchical structure and generate posterior prediction. However, I am stuck on how to showcase different insight for each geo and overall level:
Insights like:

  1. Channel contribution to revenue (waterfall kind of chart)
  2. Saturation curve
  3. How to fit budget allocator for this?

Can you guys share some direction or references, which we can refer here ?

*Data: 5 spend channels with Revenue as KPI, at different geo level (4 currently)

Basic model structure is:
with pm.Model() as bhmmm:
— parameters and other functionalities
trace = pm.sample()

Note: New to this kind of modelling , let me know if I should share any other info.

I’ve built a similar thing. All of this information will be in the trace object that you have generated, or you will be able to use the trace object to calculate them (if you have deterministic values that you didn’t save to the trace).

To your points:

  1. You likely have this as a deterministic variable, something like channel_coefficient * saturated_channel_data. These probably have channel, date, and geo level dimensions. If this object is an X-Array, you can just slice and sum the x-array any which way to see what you want to see.
  2. You likely defined a saturation function, and this saturation function took in a parameter or a few parameters, depending on the saturation function you used (logistic saturation, hill sigmoidal…). The shape of the curve is completely defined by the parameters that you would have estimated in the model. You can use the posterior estimates of these parameters to generate the saturation curves and display them. It’s important here to think about where the channel data you have lies on this curve. The curve on its own won’t tell you much if you don’t know where most of your spend exists on the curve.
  3. In my case, I built a non-linear optimiser that takes in the values from the trace and does optimisation that way. I think if you are using pymc-marketing, there is a budget optimiser that you can use which is built in. I didn’t use pymc-marketing as I wanted more flexibility in regards to hierarchies, so I can’t comment much on the built in optimiser.

Also note that if you have applied standardisation/normalisation to your metrics, you will need to reverse this in a sensible way so that your outputs have meaning.

2 Likes

Hi @Toph

Thank you for your response.

Wanted to check if you could share any sample notebook highlighting these steps - it would benefit me and many other.

Thank you for your help!

This is pretty comprehensive.

1 Like