Installation

Installation of bnlearn is straightforward.

It is advisable to create a new environment which is done as following:

conda create -n BNLEARN python=3.8
conda activate BNLEARN
_images/01_installation.png

Create environment.

Notice the last line. You need to see that your environment is now set as BNLEARN. In my case it is as following:

(BNLEARN) D:\>

bnlearn is build on top of the pgmpy library. Recommended is a conda installation for pgmpy:

conda install -c ankurankan pgmpy>="0.1.13"
# or
pip install -U pgmpy>=0.1.13
_images/02_installation.png

Install pgmpy.

Deactivate and then activate your environment if the packages are not recognized.

conda deactivate
conda activate BNLEARN

After creating the environment and installing pgmpy, you can simply install bnlearn with pip:

# Install bnlearn and if a version is readily present on your local machine, this version will be installed.
pip install bnlearn

# Make sure to have the latest version from pypi by using the -U (update) argument.
pip install -U bnlearn
_images/03_installation.png

Install bnlearn.

Validate

Lets checkout whether it works by a simple example. Start python in your console:

python

Run the following lines which should result in a figure:

import bnlearn
df = bnlearn.import_example()
model = bnlearn.structure_learning.fit(df)
G = bnlearn.plot(model)
_images/04_installation.png

import bnlearn.

Uninstalling

If you want to remove your bnlearn installation with your environment, it can be as following:

# List all the active environments. BNLEARN should be listed.
conda env list

# Remove the BNLEARN environment
conda env remove --name BNLEARN

# List all the active environments. BNLEARN should be absent.
conda env list