Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmm.plot_posterior_predictive() does not work #570

Closed
Garve opened this issue Mar 6, 2024 · 6 comments
Closed

mmm.plot_posterior_predictive() does not work #570

Garve opened this issue Mar 6, 2024 · 6 comments
Labels

Comments

@Garve
Copy link
Contributor

Garve commented Mar 6, 2024

Hi! I trained a model, and when I execute
mmm.plot_posterior_predictive(), I get

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[262], line 1
----> 1 mmm.plot_posterior_predictive()

File [~\miniconda3\envs\mmm\Lib\site-packages\pymc_marketing\mmm\base.py:303](http://localhost:8888/lab/tree/Desktop/MMM/~/miniconda3/envs/mmm/Lib/site-packages/pymc_marketing/mmm/base.py#line=302), in BaseMMM.plot_posterior_predictive(self, original_scale, **plt_kwargs)
    300 def plot_posterior_predictive(
    301     self, original_scale: bool = False, **plt_kwargs: Any
    302 ) -> plt.Figure:
--> 303     posterior_predictive_data: Dataset = self.posterior_predictive
    304     likelihood_hdi_94: DataArray = az.hdi(
    305         ary=posterior_predictive_data, hdi_prob=0.94
    306     )[self.output_var]
    307     likelihood_hdi_50: DataArray = az.hdi(
    308         ary=posterior_predictive_data, hdi_prob=0.50
    309     )[self.output_var]

File [~\miniconda3\envs\mmm\Lib\site-packages\pymc_marketing\mmm\base.py:251](http://localhost:8888/lab/tree/Desktop/MMM/~/miniconda3/envs/mmm/Lib/site-packages/pymc_marketing/mmm/base.py#line=250), in BaseMMM.posterior_predictive(self)
    248 @property
    249 def posterior_predictive(self) -> Dataset:
    250     if self.idata is None or "posterior_predictive" not in self.idata:
--> 251         raise RuntimeError("The model hasn't been fit yet, call .fit() first")
    252     return self.idata["posterior_predictive"]

RuntimeError: The model hasn't been fit yet, call .fit() first

The self.idata exists, but it does not have a posterior_predictive attribute.

pymc_marketing version 0.4.0.

@wd60622
Copy link
Contributor

wd60622 commented Mar 6, 2024

Did you set the extend = True when using the 'sample_posterior_predictive' method?

@Garve
Copy link
Contributor Author

Garve commented Mar 6, 2024

Hi!

I just trained a model and called this method. I didn't call sample_posterior_predictive explicitly anywhere.

Best
Robert

@smusch2
Copy link

smusch2 commented Mar 6, 2024

@Garve Did you run the top line shown here? It fixed my issue.

mmm.sample_posterior_predictive(X, extend_idata=True, combined=True)
mmm.plot_posterior_predictive(original_scale=True)

@juanitorduz
Copy link
Collaborator

We need a better error message for this one.

@juanitorduz juanitorduz added the MMM label Mar 7, 2024
@ulfaslak
Copy link
Contributor

ulfaslak commented Apr 3, 2024

I have run into this too. How about adding some logic that does sample_posterior_predictive inside plot_posterior_predictive if it hasn't already been done.

@wd60622
Copy link
Contributor

wd60622 commented Jun 13, 2024

#741 introduces new error message telling user to call sample_posterior_predictive method

@wd60622 wd60622 closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants