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
476 stars 46 forks source link

Parameter Learning MLE estimation is broken #27

Closed ssomanch closed 3 years ago

ssomanch commented 3 years ago

The maximum likelihood estimation in parameter learning, fit(model, df, methodtype='ml', verbose=3), estimates the CPDs using MLE but then the model returned is MaximumLiklihoodEstimator not a BayesianModel class. The code needs to be modified as below in parameter_learning.py

if config['method']=='ml' or config['method']=='maximumlikelihood':
   model.fit(df, estimator=None) # estimator as None makes it maximum likelihood estimator according pgmpy docs. 
    for cpd in model.get_cpds():
        if config['verbose']>=3: print("CPD of {variable}:".format(variable=cpd.variable))
        if config['verbose']>=3: print(cpd)
erdogant commented 3 years ago

Great! I updated and created a new release. update with:

pip install -U bnlearn

ssomanch commented 3 years ago

Great, thank you!