(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.generate("forest fire", 10, seed=1) # Creates a DAG
dag.generate_discrete_parameters(alpha=5.0, min_levels=3, max_levels=5, seed=1) # Generates parameters
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.generate("barabasi albert", 5, seed=1).plot() # Saves 'DAG.png' in working directory
Generate two 5-node Erdos-Renyi DAGs and compare them:
from baynet import DAG, metrics
dag_1 = DAG.generate("erdos_renyi", 5,seed=1)
dag_2 = DAG.generate("erdos_renyi", 5)
print(metrics.shd(dag_1, dag_2)) # prints DAG SHD, in this case 3
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
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
Release history Release notifications | RSS feed
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.3.0.tar.gz
(1.2 MB
view details)
Built Distribution
File details
Details for the file BayNet-0.3.0.tar.gz
.
File metadata
- Download URL: BayNet-0.3.0.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51d4a6d2460043ad24632808fa614f106d727ad55b3f18e618bc2927f358ab7c |
|
MD5 | 2655a9bfe1107b859269165bd77beb49 |
|
BLAKE2b-256 | 256d1439c08cd497f3affe4dc6ad6ae8321c35f8511cf3df17f045dffbeda583 |
File details
Details for the file BayNet-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: BayNet-0.3.0-py3-none-any.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 308924f8d7aa339328ddbce90ea224bf2fa72acbcb3f4a0827b917e3b03504eb |
|
MD5 | 0ce8d066dd94c106c50d1f3178ae41ab |
|
BLAKE2b-256 | 94db92ba29160830bfa070a6fd36f624a63b12b0981b97102c84498387d3ef55 |