Skip to main content

(another) Python Bayesian Network library

Project description

BayNet

BayNet is a Python library for generating, sampling data from, comparing, and visualising Bayesian Networks.

Installation

pip install BayNet

Usage

Generate a 10-node Forest Fire DAG, and parameters, then sample data from it:

from baynet import DAG
dag = DAG.forest_fire(10, .5, seed=1) # Creates a DAG
dag.generate_discrete_parameters(seed=1) # Samples parameters for each node
data = dag.sample(1_000) # Samples data, returning a pandas DataFrame

Generate a 5-node Barabasi-Albert (preferential attachment) graph and plot it:

from baynet import DAG
DAG.barabasi_albert(5, seed=1).plot() # Saves 'DAG.png' in working directory

Example DAG.png

Generate two 5-node Erdos-Renyi DAGs and compare them:

from baynet import DAG, metrics
dag_1 = DAG.erdos_renyi(5, 0.5, seed=1)
dag_2 = DAG.erdos_renyi(5, 0.5)
print(metrics.shd(dag_1, dag_2)) # prints DAG SHD, in this case 6
print(metrics.shd(dag_1, dag_2, skeleton=True)) # prints skeleton SHD, in this case 3
dag_1.compare(dag_2).plot() # saves 'comparison.png' in working directory

Example comparison.png

Taking dag_1 to be the ground truth and dag_2 to be a structure learning result:

  • Dashed red arcs represent false negatives
  • Blue arcs are represent positives
  • Green arcs represent incorrectly directed arcs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BayNet-0.2.2.tar.gz (1.2 MB view hashes)

Uploaded Source

Built Distribution

BayNet-0.2.2-py3-none-any.whl (1.3 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page