Giter Site home page Giter Site logo

pgmpy's Introduction

pgmpy

Build Status Coverage Status Code Health Join the chat at https://gitter.im/pgmpy/pgmpy

Python Library for Probabilistic Graphical Models
Documentation: pgmpy
Mailing List: [email protected]

Dependencies:

  • Python 3.3
  • NetworkX 1.9.1
  • Scipy 0.12.1
  • Numpy 1.9.2
  • Cython 0.21
  • Pandas 0.15.1

To install all the depedencies

  • Either using pip, use
pip install -r requirements.txt
  • Else using conda, use
conda install --file requirements.txt

Installation:

pgmpy is installed using distutils. If you have the tools installed to build a python extension module:

sudo python3 setup.py install

Example:

from pgmpy.models import BayesianModel
from pgmpy.factors import TabularCPD
student = BayesianModel()
# instantiates a new Bayesian Model called 'student'

student.add_nodes_from(['diff', 'intel', 'grade'])
# adds nodes labelled 'diff', 'intel', 'grade' to student

student.add_edges_from([('diff', 'grade'), ('intel', 'grade')])
# adds directed edges from 'diff' to 'grade' and 'intel' to 'grade'

"""
diff cpd:

+-------+--------+
|diff:  |        |
+-------+--------+
|easy	|	0.2	 |
+-------+--------+
|hard	|	0.8	 |
+-------+--------+
"""
diff_cpd = TabularCPD('diff', 2, [[0.2], [0.8]])

"""
intel cpd:

+-------+--------+
|intel: |        |
+-------+--------+
|dumb	|	0.5	 |
+-------+--------+
|avg	|	0.3	 |
+-------+--------+
|smart	|	0.2	 |
+-------+--------+
"""
intel_cpd = TabularCPD('intel', 3, [[0.5], [0.3], [0.2]])

"""
grade cpd:

+------+-----------------------+---------------------+
|diff: |          easy         |         hard        |
+------+------+------+---------+------+------+-------+
|intel:| dumb |  avg |  smart  | dumb | avg  | smart |
+------+------+------+---------+------+------+-------+
|gradeA| 0.1  | 0.1  |   0.1   |  0.1 |  0.1 |   0.1 |
+------+------+------+---------+------+------+-------+
|gradeB| 0.1  | 0.1  |   0.1   |  0.1 |  0.1 |   0.1 |
+------+------+------+---------+------+------+-------+
|gradeC| 0.8  | 0.8  |   0.8   |  0.8 |  0.8 |   0.8 |
+------+------+------+---------+------+------+-------+
"""
grade_cpd = TabularCPD('grade', 3,
					   [[0.1,0.1,0.1,0.1,0.1,0.1],
                        [0.1,0.1,0.1,0.1,0.1,0.1], 
                        [0.8,0.8,0.8,0.8,0.8,0.8]],
					   evidence=['intel', 'diff'],
					   evidence_card=[3, 2])

student.add_cpds(diff_cpd, intel_cpd, grade_cpd)

# Finding active trail
student.active_trail_nodes('diff')

# Finding active trail with observation
student.active_trail_nodes('diff', observed='grade')

pgmpy's People

Contributors

abinashpanda avatar ankurankan avatar ashwch avatar demyanov avatar elkbrsathuji avatar erotemic avatar gitter-badger avatar jaidevd avatar jp111 avatar khalibartan avatar kislayabhi avatar kshitij10496 avatar navinchandak avatar palashahuja avatar pandaabinash avatar pratyakshs avatar saketkc avatar siteshjaiswal avatar snigam3112 avatar vivek425ster avatar yashu-seth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.