Skip to content

Commit

Permalink
Add prior predictive example notebook (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanitorduz authored and twiecki committed Sep 10, 2024
1 parent 53e2f6d commit 7f469c4
Show file tree
Hide file tree
Showing 4 changed files with 4,365 additions and 3,693 deletions.
8,046 changes: 4,362 additions & 3,684 deletions docs/source/notebooks/mmm/mmm_example.ipynb

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions pymc_marketing/mmm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ def posterior_predictive(self) -> Dataset:
)
return self.idata["posterior_predictive"]

def plot_prior_predictive(
self, samples: int = 1_000, **plt_kwargs: Any
) -> plt.Figure:
def plot_prior_predictive(self, **plt_kwargs: Any) -> plt.Figure:
prior_predictive_data: az.InferenceData = self.prior_predictive

likelihood_hdi_94: DataArray = az.hdi(ary=prior_predictive_data, hdi_prob=0.94)[
Expand Down
1 change: 0 additions & 1 deletion pymc_marketing/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ def sample_prior_predictive(
if not hasattr(self, "model"):
self.build_model(X_pred, y_pred)

self._data_setter(X_pred, y_pred)
with self.model: # sample with new input data
prior_pred: az.InferenceData = pm.sample_prior_predictive(samples, **kwargs)
self.set_idata_attrs(prior_pred)
Expand Down
7 changes: 2 additions & 5 deletions tests/mmm/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import pytest
from matplotlib import pyplot as plt

from pymc_marketing.mmm.delayed_saturated_mmm import (
MMM,
BaseMMM,
)
from pymc_marketing.mmm.delayed_saturated_mmm import MMM, BaseMMM
from pymc_marketing.mmm.preprocessing import MaxAbsScaleTarget

seed: int = sum(map(ord, "pymc_marketing"))
Expand Down Expand Up @@ -124,7 +121,7 @@ class ToyMMM(BaseMMM, MaxAbsScaleTarget):
@pytest.mark.parametrize(
argnames="func_plot_name, kwargs_plot",
argvalues=[
("plot_prior_predictive", {"samples": 3}),
("plot_prior_predictive", {}),
("plot_posterior_predictive", {}),
("plot_posterior_predictive", {"original_scale": True}),
("plot_posterior_predictive", {"ax": plt.subplots()[1]}),
Expand Down

0 comments on commit 7f469c4

Please sign in to comment.