Title:
KeyError: ‘dayofyear’ in sample_posterior_predictive Call in PyMC-Marketing
Question:
Hello, I’m using PyMC-Marketing to build a Marketing Mix Model (MMM). While running sample_posterior_predictive on my model, I encountered a KeyError: 'dayofyear'. I would appreciate any help or guidance on resolving this issue.
Environment:
- PyMC-Marketing version: 0.10.0
- PyMC version: 5.15.1
- Python version: 3.12
- System: MacOS/Windows/Linux (specify your system)
Problem Description:
After setting up my model, I attempted to call sample_posterior_predictive using a new DataFrame (temp) as input data. However, I received the following error:
Error Message (partial):
json
{
"name": "KeyError",
"message": "'dayofyear'",
"stack": "---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File ~/work/.venv/lib/python3.12/site-packages/pymc/model/core.py:1564, in Model.__getitem__(self, key)
1563 try:
-> 1564 return self.named_vars[self.name_for(key)]
1565 except KeyError:
KeyError: 'dayofyear'
...
KeyError: 'dayofyear'
Code Snippet:
Here’s the code where the error occurs. I’m using a DataFrame called temp as the input without the dayofyear variable.
mmm.sample_posterior_predictive(temp,
original_scale=False,
var_names=["control_contributions"])
Attempts to Resolve:
- I tried adding a
dayofyearvariable totemp, but it does not appear to be defined inmmm.named_vars. - I inspected
control_contributionsbut found no explicit reference todayofyear. - I considered that the model might have defined seasonality based on
dayofyearduring initialization, but I could not find a clear indication in the setup code.
Questions:
- Does PyMC-Marketing require the
dayofyearvariable for seasonality in posterior predictive sampling, or is there a recommended approach to include this variable if necessary? - I’m unsure why
dayofyearis needed in thecontrol_contributionsvariable, as I couldn’t find a direct reference to it. Could you clarify typical scenarios where this variable might be expected? - Is there a way to configure the model to make
dayofyearoptional in the posterior predictive sampling?
Additional Details:
- I intended to include seasonality and trend in the model setup, but
dayofyearwas not explicitly mentioned. - Due to data sensitivity, I can share relevant code snippets if needed.
Thank you for your help!
This is my first time posting a question, so I would appreciate any guidance or patience with my query. If additional information is needed, please feel free to ask.