Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

+1 vote
by (4.2k points)

I'm searching for the most appropriate tool for python3.x on Windows to create a Bayesian Network, learn its parameters from data and perform the inference.

The network structure I want to define myself as follows: enter image description here

It is taken from this paper.

All the variables are discrete (and can take only 2 possible states) except "Size" and "GraspPose", which are continuous and should be modeled as Mixture of Gaussians.

Authors use Expectation-Maximization algorithm to learn the parameters for conditional probability tables and Junction-Tree algorithm to compute the exact inference.

As I understand all is realised in MatLab with Bayes Net Toolbox by Murphy.

I tried to search something similar in python and here are my results:

  1. Python Bayesian Network Toolbox Web-site doesn't work, project doesn't seem to be supported.
  2. BayesPy I think this is what I actually need, but I fail to find some examples similar to my case, to understand how to approach construction of the network structure.
  3. PyMC seems to be a powerful module, but I have problems with importing it on Windows 64, python 3.3. I get error when I install development version

    WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.


  1. libpgm ( Exactly what I need, unfortunately not supported by python 3.x
  2. Very interesting actively developing library: PGMPY. Unfortunately continuous variables and learning from data is not supported yet.

Any advices and concrete examples will be highly appreciated.

1 Answer

+2 votes
by (6.8k points)

Pomegranate is a package for probabilistic models in Python that is implemented in cython for speed. Its the focus is on merging the easy-to-use scikit-learn API with the modularity that comes with probabilistic modeling to allow users to specify complicated models without needing to worry about implementation details. The models are built from the ground up with big data processing in mind and so natively support features like out-of-core learning and parallelism. 


pomegranate is pip-installable using pip install pomegranate and conda-installable using conda install pomegranate. 

It looks like pomegranate was recently updated to include Bayesian Networks.

Here is an example of how to use it.

from pomegranate import *

import numpy as np


bnet = BayesianNetwork.from_samples(mydb)



print (bnet.probability([[1,2,8]]))


Browse Categories