Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bayesian network in Python: both construction and sampling

For a project, I need to create synthetic categorical data containing specific dependencies between the attributes. This can be done by sampling from a pre-defined Bayesian Network. After some exploration on the internet, I found that Pomegranate is a good package for Bayesian Networks, however - as far as I'm concerned - it seems unpossible to sample from such a pre-defined Bayesian Network. As an example, model.sample() raises a NotImplementedError (despite this solution says so).

Does anyone know if there exists a library which provides a good interface for the construction and sampling of/from a Bayesian network?

like image 765
Rutger Mauritz Avatar asked Nov 29 '19 15:11

Rutger Mauritz


People also ask

How Bayesian network is construct?

Bayesian networks may be constructed either manually with knowledge of the underlying domain, or automatically from a large dataset by appropriate software. Keywords: Bayesian network, Causality, Complexity, Directed acyclic graph, Evidence, Factor, Graphical model, Node.

What is the difference between Bayesian network and Bayesian belief network?

A Bayesian Network captures the joint probabilities of the events represented by the model. A Bayesian belief network describes the joint probability distribution for a set of variables.

What are the types of Bayesian network modeling connections?

Consider this concept in case of the three basic connections (serial, diverging, and converging) that are possible in Bayesian networks (see Figure 1): ...

What is Bayesian network briefly discuss how a Bayesian network is constructed?

A Bayesian network is a probability model defined over an acyclic directed graph. It is factored by using one conditional probability distribution for each variable in the model, whose distribution is given conditional on its parents in the graph.


1 Answers

Using pyAgrum, you just have to :

#import pyAgrum
import pyAgrum as gum

# create a BN
bn=gum.fastBN("A->B[3]<-C{yes|No}->D")
# specify some CPTs (randomly filled by fastBN)
bn.cpt("A").fillWith([0.3,0.7])

# and then generate a database
gum.generateCSV(bn,"sample.csv",1000,with_labels=True,random_order=False) 
# which returns the LL(database)

the code in a notebook

See http://webia.lip6.fr/~phw/aGrUM/docs/last/notebooks/ for more notebooks using pyAgrum

Disclaimer: I am one of the authors of pyAgrum :-)

like image 139
Pierre-Henri Wuillemin Avatar answered Sep 28 '22 17:09

Pierre-Henri Wuillemin