Let's now see some coding examples using pgmpy
, to represent joint distributions and independencies. Here, we will mostly work with IPython and pgmpy
(and a few other libraries) for coding examples. So, before moving ahead, let's get a basic introduction to these.
IPython is a command shell for interactive computing in multiple programming languages, originally developed for the Python programming language, which offers enhanced introspection, rich media, additional shell syntax, tab completion, and a rich history. IPython provides the following features:
Powerful interactive shells (terminal and Qt-based)
A browser-based notebook with support for code, text, mathematical expressions, inline plots, and other rich media
Support for interactive data visualization and use of GUI toolkits
Flexible and embeddable interpreters to load into one's own projects
Easy-to-use and high performance tools for parallel computing
You can install IPython using the following command:
>>> pip3 install ipython
To start the IPython command shell, you can simply type ipython3
in the terminal. For more installation instructions, you can visit http://ipython.org/install.html.
pgmpy is a Python library to work with Probabilistic Graphical models. As it's currently not on PyPi, we will need to build it manually. You can get the source code from the Git repository using the following command:
>>> git clone https://github.com/pgmpy/pgmpy
Now cd
into the cloned directory switch branch for version used in this book and build it with the following code:
>>> cd pgmpy >>> git checkout book/v0.1 >>> sudo python3 setup.py install
For more installation instructions, you can visit http://pgmpy.org/install.html.
With both IPython and pgmpy installed, you should now be able to run the examples in the book.