erdogant / bnlearn

Python library for learning the graphical structure of Bayesian networks, parameter learning, inference and sampling methods.
https://erdogant.github.io/bnlearn
Other
463 stars 45 forks source link

Issue with the sampling method - AttributeError: type object 'object' has no attribute 'dtype' #62

Closed agcgit closed 1 year ago

agcgit commented 1 year ago

The following code result in error

I'm using python 3.8

Import library

import bnlearn as bn print(bn.version) image

model = bn.import_DAG('sprinkler', CPD=True) df = bn.sampling(model, n=1000, methodtype='bayes')

df.head()

image

erdogant commented 1 year ago

Can you check the version of pgmpy that you are using?

import pgmpy
pgmpy.__version__

I use version '0.1.18' which does not give this error. If you have a older version, try to update first with: pip install -U pgmpy

agcgit commented 1 year ago

my version of pgmpy is '0.1.20', I tried to to downgrade to 0.1.18 but it still giving giving the same error

erdogant commented 1 year ago

If you try the colab notebook example, does it also throw an error?

agcgit commented 1 year ago

error in colab notebook


TypeError Traceback (most recent call last) in 1 model = bn.import_DAG('sprinkler', CPD=True) ----> 2 df = bn.sampling(model, n=10000,methodtype='bayes') 3

TypeError: sampling() got an unexpected keyword argument 'methodtype'

however if I remove the methodtype argument its working.

erdogant commented 1 year ago

It seems that many packages require Python >3.8 or higher. Colab runs in python 3.7 (I did not realize this) and therefore older versions of packages are installed (including bnlearn). But try to create an environment with >python3.8, (3.10 or so). This will likely solve your issue.

erdogant commented 1 year ago

I am closing this issue. Please re-open if required.