erdogant / bnlearn

Python package for Causal Discovery by learning the graphical structure of Bayesian networks. Structure Learning, Parameter Learning, Inferences, Sampling methods.
https://erdogant.github.io/bnlearn
Other
480 stars 46 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 2 years 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 2 years 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 2 years 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 2 years ago

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

agcgit commented 2 years 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 2 years 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.