Setting priors raises ValueError: need at least one array to concatenate
See original GitHub issueHi! I was trying to follow the docs to set custom priors on some made up data but kept hitting this numpy error in weird places. Including an example, diagnostics, and the results of my investigation here:
Example:
import bambi as bmb
import pandas as pd
import numpy as np
df = pd.DataFrame(
dict(y=[0, 1, 0, 0, 1, 0], x_1=np.random.uniform(size=(6,)), x_2=np.random.uniform(size=(6,))),
)
priors = {
"x_1": bmb.Prior("TruncatedNormal", sigma=1, mu=0, lower=0),
"x_2": bmb.Prior("TruncatedNormal", sigma=1, mu=0, upper=0),
}
model = bmb.Model(
formula="y ~ x_1 + x_2", data=df, family="bernoulli", priors=priors
)
model.build()
...
~/.pyenv/versions/3.8.10/envs/jupyter/lib/python3.8/site-packages/numpy/core/shape_base.py in hstack(tup)
343 return _nx.concatenate(arrs, 0)
344 else:
--> 345 return _nx.concatenate(arrs, 1)
346
347
<__array_function__ internals> in concatenate(*args, **kwargs)
ValueError: need at least one array to concatenate
Diagnostics:
import sys
print("sys: ", sys.version)
print("np: ", np.__version__)
print("pd: ", pd.__version__)
print("bmb: ", bmb.__version__)
sys: 3.8.10 (default, Jun 24 2021, 16:50:28)
[Clang 12.0.5 (clang-1205.0.22.11)]
np: 1.21.2
pd: 1.3.3
bmb: 0.6.3
What i tried
- no results in project tracker
- Added/removed/changed the
automatic_priors
setting. - Added/removed/changed the
auto_scale
setting. - I put one term’s prior into a tuple, and then the model built, but it does not look like the prior took:
priors = {
("x_1",): bmb.Prior("TruncatedNormal", sigma=1, mu=0, lower=0),
"x_2": bmb.Prior("TruncatedNormal", sigma=1, mu=0, upper=0),
}
model = bmb.Model(
formula="y ~ x_1 + x_2", data=df, family="bernoulli", priors=priors
)
model.build()
model.plot_priors()
You can see that x_1 is not given the correct prior whereas x_2 is.
- Setting auto_scale=False on the model allows everything to build, but the priors are not correct:
model = bmb.Model(
formula="y ~ x_1 + x_2", data=df, family="bernoulli", priors=priors, auto_scale=False
)
model.build()
model.plot_priors()
This feels like a numpy incompatibility- are these any known such issues?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
ValueError: need at least one array to concatenate
The problem seems to be in np.concatenate where it expects an array of arrays and it's not receiving ...
Read more >ValueError: need at least one array to concatenate · Issue #3628
Hi, concatenation from an empty array will raise this error, and there is size mismatch between your model and loaded state dict (e.g.,...
Read more >Merge, join, concatenate and compare - Pandas
Merge, join, concatenate and compare#. pandas provides various facilities for easily combining together Series or DataFrame with various kinds of set logic ...
Read more >solution-dsa01 | Kaggle
... FileNotFoundError Traceback (most recent call last) ... internals> in concatenate(*args, **kwargs) ValueError: need at least one array to concatenate.
Read more >ValueError: Not enough samples to build a trace - Questions
I keep getting an error on a small test case. ... line 1530, in _choose_chains raise ValueError("Not enough samples to build a trace....
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
This is fixed in #430
Glad it helped! And thanks for raising this issue. I wasn’t aware of it. I’ll try to fix it for the next release 😃