erdogant / bnlearn

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

after DAG is created unable to access 'adjmat' and learn the parameter from a data #7

Closed Danielmulerr closed 3 years ago

Danielmulerr commented 3 years ago

here i have created a list of edges that are already learned by the structure learning edges = [('no_comment', 'O'), ('no_priority_change', 'priority'), ('O', 'no_fixversion_change'), ('O', 'perofdelay'), ('O', 'no_fixversion'), ('O', 'repetition')] DAG = bn.make_DAG(edges)

use the features that are included in the DAG to select the data

_data_selected = data[['no_comment', 'no_priority_change', 'priority', 'no_fixversion_change', 'perofdelay', 'no_fixversion', 'repetition','O']]

use the dataframe with the selected features for parameter learning

model_p = bn.parameter_learning.fit(DAG, _data_selected) the error is as followa, Traceback (most recent call last): File "E:/dn/Issue/bayesian learning/bn.py", line 167, in _parameter_learning(dataset[1]) File "E:/dn/Issue/bayesian learning/bn.py", line 153, in _parameter_learning _model_p = bn.parameter_learning.fit(DAG, _data_selected) File "C:\ProgramData\Anaconda3\envs\tensor2\lib\site-packages\bnlearn\parameter_learning.py", line 72, in fit adjmat = model['adjmat'] File "C:\ProgramData\Anaconda3\envs\tensor2\lib\site-packages\networkx\classes\graph.py", line 475, in getitem return self.adj[n] File "C:\ProgramData\Anaconda3\envs\tensor2\lib\site-packages\networkx\classes\coreviews.py", line 81, in getitem return AtlasView(self._atlas[name]) KeyError: 'adjmat'

I believe the problem is it is unable to get the adjmat values. please is there is any way around this let me know ... I am in hurry.

erdogant commented 3 years ago

Can you plot the DAG?

bn.plot(DAG)

Is _data_selected numerical without missing values?

erdogant commented 3 years ago

I created a update, maybe it solved your issue as well. The new version of networkx gave some issues. Install the latest bnlearn version as following:

pip install -U bnlearn
import bnlearn as bn
print(bn.__version__)
# Should be >= 0.3.8

If this did not solve your issues, can you send me a small part of your data? That can help to replicate your issue.

Danielmulerr commented 3 years ago

i will check the new version. does the parameter learning work for continuous attributes/featurs ? if not how can i deal with it ?

erdogant commented 3 years ago

There is no implementation yet for continuous values. Its on my long list of todos ;)

Danielmulerr commented 3 years ago

thank you for your reply. can you suggest me any other tool that can do it, or if I can apply data discretization on the values on this library?

erdogant commented 3 years ago

You can think if descritizing your data. Maybe there is a “natural” point that you can use? As an example, if you have temperature you can decide to make 2 or more categories such as Cold and warm. Otherwise you can try to look into the pgmpy, maybe here: https://pgmpy.org/factors.html#continuous