How to print the printing full cpd from pgmpy?

Viewed 441

I'm trying to get the example in Insurance data representation with Bayesian networks to work. See the section Maximum Likelihood Estimation. The data I got from the bnlearn package in R and then uploaded it my google drive. The data

The picture below shows ... I believe this is showing missing columns. How do I fix the code to display the correct information?

enter image description here

from pgmpy.models import BayesianModel

model = BayesianModel([('Antilock', 'Accident'), ('DrivingSkill', 'DrivQuality'), ('DrivQuality', 'Accident')])

# Maximum Likelihood Estimation
from pgmpy.estimators import MaximumLikelihoodEstimator 
mle = MaximumLikelihoodEstimator(model, df)

# Pour toutes les variables :
model.fit(df, estimator=MaximumLikelihoodEstimator)
for cpd in model.get_cpds():
  print(cpd)

Note1: code to get the data from R

data(insurance)

write.csv(insurance,"C:/Users/Administrator/OneDrive/University of London/AI/Assignment 1/insurance.csv")

Note2: if you are running this in colab you will need to install the package

!pip install pgmpy
1 Answers
  1. Open file "pgmpy/factors/discrete/CPD.py"

  1. In class "TabularCPD(DiscreteFactor)",

    fine the line "cdf_str = self._truncate_strtable(cdf_str)"

    (This line is in "def _make_table_str (~)")


  1. cdf_str = self._truncate_strtable(cdf_str)

    make this line deactivate by add "#" --> # cdf_str = self._truncate_strtable(cdf_str)

Related