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
589 stars 138 forks source link

Running MMM example NB raises KeyError: 'intercept' #603

Closed twiecki closed 3 months ago

twiecki commented 3 months ago

PyMC-Marketing v 0.4.0.

mmm = DelayedSaturatedMMM(
    model_config = my_model_config,
    sampler_config = my_sampler_config,
    date_column="date_week",
    channel_columns=["x1", "x2"],
    control_columns=[
        "event_1",
        "event_2",
        "t",
    ],
    adstock_max_lag=8,
    yearly_seasonality=2,
)
KeyError                                  Traceback (most recent call last)
Cell In[42], line 1
----> 1 mmm.fit(X=X, y=y, target_accept=0.95, chains=4, random_seed=rng)

File ~/micromamba/envs/pymc5/lib/python3.11/site-packages/pymc_marketing/model_builder.py:466, in ModelBuilder.fit(self, X, y, progressbar, predictor_names, random_seed, **kwargs)
    464 if self.X is None or self.y is None:
    465     raise ValueError("X and y must be set before calling build_model!")
--> 466 self.build_model(self.X, self.y)
    468 sampler_config = self.sampler_config.copy()
    469 sampler_config["progressbar"] = progressbar

File ~/micromamba/envs/pymc5/lib/python3.11/site-packages/pymc_marketing/mmm/delayed_saturated_mmm.py:309, in BaseDelayedSaturatedMMM.build_model(self, X, y, **kwargs)
    250 def build_model(
    251     self,
    252     X: pd.DataFrame,
    253     y: Union[pd.Series, np.ndarray],
    254     **kwargs,
    255 ) -> None:
    256     """
    257     Builds a probabilistic model using PyMC for marketing mix modeling.
    258 
   (...)
    305             )
    306     """
    308     self.intercept_dist = self._get_distribution(
--> 309         dist=self.model_config["intercept"]
    310     )
    311     self.beta_channel_dist = self._get_distribution(
    312         dist=self.model_config["beta_channel"]
    313     )
    314     self.lam_dist = self._get_distribution(dist=self.model_config["lam"])

KeyError: 'intercept'
cetagostini commented 3 months ago

@juanitorduz should we create a patch for this like 0.4.0.1? I was checking and it's solve in 0.4.2.

Even though very strange error because everything around the config looks okay, I can take a look but let me know how we should move forward ✌🏻

juanitorduz commented 3 months ago

If it's working on 0.4.2, we can close it, right?

juanitorduz commented 3 months ago

I can also verify the MMM nb works on 0.4.2 end-to-enf

cetagostini commented 3 months ago

Great if it's working for both the version 0.4.2 then I'll close it.