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

the problem of the methodtype "tan" in the function "bn.structure_learning.fit" #78

Closed Garylee123456 closed 9 months ago

Garylee123456 commented 1 year ago

When I run model = bn.structure_learning.fit(data, methodtype='tan', root_node='XX1', class_node='Y') in my Python terminal, I get the following error: AttributeError: 'Series' object has no attribute 'iteritems'. I noticed that in the function '_conditional_edge_weights_fn' in line 330 of the file located at '\venv\lib\site-packages\pgmpy\estimators\TreeSearch.py', the code still uses 'for index, marg_prob in cond_marginal.iteritems()' instead of 'for index, marg_prob in cond_marginal.items()'. After I made this change to the code, my project was able to run. Therefore, I suggest fixing the code in TreeSearch.py as mentioned above.

erdogant commented 1 year ago

I created a new version with a temporarily fix by freezing pandas to 1.5.3. This issue occurs because iteritems is removed from pandas >= 2.0.0 but not yet incorporated into pgmpy.

Update to the latest version with: pip install -U bnlearn