plot_ppc - KeyError: "['y'] var names are not present in dataset"
See original GitHub issueHi, I’ve had troubles using plot_ppc
in a project I’m working on, so I tried to reproduce it using the quickstart pystan example. This is the code I’m using:
schools_code = """
data {
int<lower=0> J;
real y[J];
real<lower=0> sigma[J];
}
parameters {
real mu;
real<lower=0> tau;
real theta[J];
}
model {
mu ~ normal(0, 5);
tau ~ cauchy(0, 5);
theta ~ normal(mu, tau);
y ~ normal(theta, sigma);
}
generated quantities {
vector[J] log_lik;
vector[J] y_hat;
for (j in 1:J) {
log_lik[j] = normal_lpdf(y[j] | theta[j], sigma[j]);
y_hat[j] = normal_rng(theta[j], sigma[j]);
}
}
"""
schools_dat = {'J': 8,
'y': [28, 8, -3, 7, -1, 1, 18, 12],
'sigma': [15, 10, 16, 11, 9, 11, 10, 18]}
sm = pystan.StanModel(model_code=schools_code, verbose=False)
fit = sm.sampling(data=schools_dat, iter=1000, chains=4)
data = az.from_pystan(posterior=fit,
posterior_predictive='y_hat',
observed_data=['y'],
log_likelihood='log_lik',
coords={'school': schools},
dims={'theta': ['school'], 'y': ['school'], 'log_lik': ['school'], 'y_hat': ['school'], 'theta_tilde': ['school']})
az.plot_ppc(data)
This raises:
KeyError: "['y'] var names are not present in dataset"
which is exactly the kind of error I got in my own project… I guess I’m doing something wrong, here, but I can’t figure out what it is.
Any help would be appreciated… thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Getting an error I'm not Familiar with Trying to plot the ppc
I'm getting two errors when trying to use arviz to plot_ppc. ... KeyError: 'var names: "[\'y\'] are not present" in dataset'.
Read more >Getting KeyError when setting dataset column to variable with ...
If you want to use filtering with a boolean-mask, you need to use loc , and if you just want a column you...
Read more >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 - Rollbar
When an item in a dictionary is accessed using a key, and the key is not found within the set of keys of...
Read more >What is KeyError in Python? Dictionary and Handling Them
Here I am trying to access a key called “D” which is not present in the dictionary. Hence, the error is thrown as...
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
Hello. I’d like to work on this issue!
I understand. I will make the changes accordingly.