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

Add prior predictive example notebook #787

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading