Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  Asthma 
pyAgrum 0.16.3   
Zipped notebooks   
generation: 2019-10-20 09:16  

Creative Commons License
This pyAgrum's notebook is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

In [1]:
#from pylab import *
import matplotlib.pyplot as plt

# import the computation tools of aGrUM
import pyAgrum as gum

# import the graphical display functions
import pyAgrum.lib.notebook as gnb
In [2]:
# load the "asthme" Bayesian network
bn=gum.loadBN('res/asthma.bif')
In [3]:
# display the Bayesian network
gnb.showBN(bn,size='7',nodeColor={n:0.9 for n in bn.names()},cmap=plt.get_cmap('Blues'))
G hour hour traffic traffic hour->traffic weather weather accident accident weather->accident accident->traffic pollution pollution traffic->pollution asthma asthma pollution->asthma
In [4]:
# display the conditional probability table of asthme given pollution
gnb.showPotential(bn.cpt(bn.idFromName('asthma')),digits=4)
asthma
pollution
crisis
no_crisis
1
0.10000.9000
2
0.21130.7887
3
0.19720.8028
4
0.28240.7176
5
0.47460.5254
6
0.52300.4770
7
0.63410.3659
8
0.82570.1743
9
0.85370.1463
10
0.90910.0909
In [5]:
# display the probability distribution of Variable "trafic"
gnb.showPosterior (bn, {}, "traffic" )
In [6]:
# display the probability distribution of Variable "pollution"
gnb.showPosterior ( bn, {}, "pollution")
In [7]:
# display the distribution somewhat differently
gum.getPosterior ( bn, {}, "pollution")
Out[7]:
pollution
1
2
3
4
5
6
7
8
9
10
0.00000.03550.42330.27880.14750.06290.01640.02190.00820.0055
In [8]:
# more interesting: display the posterior distribution of "asthme"
# given that we observed that heure=8 and meteo=nuageux
gnb.showPosterior (bn, {'hour' : 8, 'weather' : 'cloudy'}, "asthma" )
In [9]:
# show the posterior distributions of all the variables given that
# we observed that heure=8 and meteo=nuageux.
# the tables in beige represent the observations
gnb.showInference(bn,size="7",evs={'hour' : 8, 'weather' : 'cloudy'})
structs Inference in   0.52ms hour traffic hour->traffic weather accident weather->accident accident->traffic pollution traffic->pollution asthma pollution->asthma
In [10]:
gnb.showInference(bn,size="7",evs={'hour': 7, 'accident' : 'yes'})
structs Inference in   1.08ms hour traffic hour->traffic weather accident weather->accident accident->traffic pollution traffic->pollution asthma pollution->asthma
In [ ]: