Key error 'y' for from_pystan function
See original GitHub issueHello,
I am new to Arviz. I was just trying to import PyStan model to Arviz by using “from_pystan” function but I get key error for ‘y’. I could not pass this initial step. Excuse me for this naive question.
eight_school_data = {
'J': 8,
'y': np.array([28., 8., -3., 7., -1., 1., 18., 12.]),
'sigma': np.array([15., 10., 16., 11., 9., 11., 10., 18.])
}
stan_model = pystan.StanModel(model_code=schools_code)
fit = stan_model.sampling(chains=1, data=eight_school_data, control={"adapt_delta" : 0.9})
stan_data = az.from_pystan(
posterior=fit,
posterior_predictive='y_hat',
observed_data=['y'],
log_likelihood={'y': 'log_lik'},
coords={'school': np.arange(eight_school_data['J'])},
dims={
'theta': ['school'],
'y': ['school'],
'log_lik': ['school'],
'y_hat': ['school'],
'theta_tilde': ['school']
}
)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >How to Fix KeyError Exceptions in Python
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >I'm getting Key error in python
A KeyError generally means the key doesn't exist. So, are you sure the path key exists? From the official python docs: exception KeyError....
Read more >What is KeyError in Python? Dictionary and Handling Them
KeyError in Python is raised when you attempt to access a key that is not in a dictionary.
Read more >Python KeyError Exception Handling Examples
Python KeyError is raised when we try to access a key from dict, which doesn't exist. It's one of the built-in exception classes...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi Oriol, your solution for the latest release worked for me. Thanks.
I think I know what is happening, the docs are for development version, not for latest release, and the option to use a dict as log_likelihood arg is only available in development version, there are two possible solutions.
I’d recommend installing the development version. The code should work, and log_likelihood group will be present like in cookbook.
Otherwise, use
log_likelihood="log_lik"
which will work with latest release. In this case there will be no log likelihood group, the data will be in sample stats.