-
Notifications
You must be signed in to change notification settings - Fork 252
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
plot_prior_predictive() gives error "RuntimeError: The model hasn't been fit yet, call .fit() first" #410
Comments
You probably have to call |
Thanks for the reply @ricardoV94 . It seems that calling It seems to be setting Replacing that line with the following worked for me me: |
This is because A work-around for now is to build the model manually, and then run mmm.build_model(X=X, y=y.to_numpy()) # `to_numpy` because at that point `y` hasn't been cast to numpy array yet, so will fail otherwise
with mmm.model:
mmm.idata = pm.sample_prior_predictive()
mmm.plot_prior_predictive(); However, this solution doesn't work to solve the bug in the codebase, because everything is I also think |
Thanks @AlexAndorra this worked perfectly! Is this the only workaround at the moment? If I understand correctly, X and y are only needed to get the dates and the preprocessed y to plot the observed data, so the data has not been preprocessed yet because that happens until we call the fit method and not when we call build_model. Should we only use this workaround after fit then? Just wondering if X and y need to be the X_train and y_train respectively to have the same length for other plots. |
Hi @AlfredoJF The X variable does make a difference as it will provide the information for scaling, media inputs, and control variables as well. A similar workflow comes from the lift tests integration of passing X_train to build_model method: mmm = DelayedSaturatedMMM(...)
mmm.build_model(X_train, y_train) # This does work with y_train = pd.Series now!
mmm.add_lift_test_measurements(...)
mmm.fit(X_train, y_train) # duplicated input as the build model |
def plot_prior_predictive(
self, samples: int = 1_000, **plt_kwargs: Any
) -> plt.Figure:
prior_predictive_data: az.InferenceData = self.prior_predictive
However, after In the meantime, to hack together a prior predictive plot, the internals of the above plotting method could probably be copy/pasted into a notebook and tweaked into a solution. |
Hello!
Using the example mmm notebook on the pymc marketing page, I created a basic model using the DelayedSaturatedMMM class.
I am able to .fit() the model and run through all the functions outlined in the notebook, however when I try to run .plot_prior_predictve() I get the above error. Any ideas why this may be?
The text was updated successfully, but these errors were encountered: