Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  learningClassifier 
pyAgrum 0.16.2   
Zipped notebooks   
generation: 2019-10-02 10:58  

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

In [1]:
import sys
import os

import numpy as np

import pyAgrum as gum

%matplotlib inline
from pyAgrum.lib.bn2roc import showROC
In [2]:
bn=gum.loadBN(os.path.join("res","alarm.dsl"))
In [3]:
gum.generateCSV(bn,os.path.join("out","learn.csv"),10000,visible=True,with_labels=True)
print()
gum.generateCSV(bn,os.path.join("out","train.csv"),1000,visible=True,with_labels=True)
 out/learn.csv : [ ########################################################### ] 100%
Log2-Likelihood : -150711.56508661472

 out/train.csv : [ ########################################################### ] 100%
Log2-Likelihood : -15081.453714788286
Out[3]:
-15081.453714788286

Learning a BN from learn.csv

In [4]:
# Learning a BN from the database
learner=gum.BNLearner(os.path.join("out","train.csv"))

# # Hill-Climbing
learner.useGreedyHillClimbing()
bn2=learner.learnBN()
bn2.setProperty("name","Learned_{0}s".format(learner.currentTime()))
In [5]:
import pyAgrum.lib.notebook as gnb
gnb.showBN(bn2,size="8")
G PAP PAP ERRCAUTER ERRCAUTER PAP->ERRCAUTER VENTALV VENTALV ARTCO2 ARTCO2 VENTALV->ARTCO2 PVSAT PVSAT VENTALV->PVSAT INTUBATION INTUBATION VENTALV->INTUBATION TPR TPR BP BP TPR->BP ANAPHYLAXIS ANAPHYLAXIS TPR->ANAPHYLAXIS HR HR CATECHOL CATECHOL HR->CATECHOL HR->ERRCAUTER ERRLOWOUTPUT ERRLOWOUTPUT HR->ERRLOWOUTPUT CO CO HR->CO KINKEDTUBE KINKEDTUBE PRESS PRESS KINKEDTUBE->PRESS HREKG HREKG HREKG->ERRCAUTER HRBP HRBP HREKG->HRBP LVEDVOLUME LVEDVOLUME PCWP PCWP LVEDVOLUME->PCWP LVFAILURE LVFAILURE LVEDVOLUME->LVFAILURE CVP CVP LVEDVOLUME->CVP VENTMACH VENTMACH VENTMACH->CATECHOL VENTTUBE VENTTUBE VENTMACH->VENTTUBE VENTMACH->INTUBATION LVFAILURE->ERRLOWOUTPUT HISTORY HISTORY LVFAILURE->HISTORY HRSAT HRSAT HRSAT->HR HRSAT->HREKG HRSAT->ERRCAUTER HRSAT->HRBP DISCONNECT DISCONNECT DISCONNECT->VENTTUBE MINVOL MINVOL SAO2 SAO2 SAO2->KINKEDTUBE SAO2->CATECHOL SAO2->HRSAT STROKEVOLUME STROKEVOLUME STROKEVOLUME->LVFAILURE STROKEVOLUME->CO HYPOVOLEMIA HYPOVOLEMIA STROKEVOLUME->HYPOVOLEMIA CO->BP SHUNT SHUNT SHUNT->SAO2 VENTLUNG VENTLUNG VENTLUNG->VENTALV VENTLUNG->ARTCO2 VENTLUNG->KINKEDTUBE VENTLUNG->MINVOL VENTLUNG->INTUBATION FIO2 FIO2 FIO2->KINKEDTUBE FIO2->PVSAT PULMEMBOLUS PULMEMBOLUS PULMEMBOLUS->PAP PULMEMBOLUS->SHUNT PVSAT->SAO2 HRBP->HR HRBP->ERRLOWOUTPUT VENTTUBE->KINKEDTUBE VENTTUBE->PRESS VENTTUBE->ERRLOWOUTPUT VENTTUBE->VENTLUNG EXPCO2 EXPCO2 VENTTUBE->EXPCO2 INSUFFANESTH INSUFFANESTH INSUFFANESTH->CATECHOL HYPOVOLEMIA->LVEDVOLUME EXPCO2->VENTALV EXPCO2->ARTCO2 EXPCO2->MINVOL EXPCO2->VENTLUNG ANAPHYLAXIS->PRESS MINVOLSET MINVOLSET MINVOLSET->VENTMACH INTUBATION->PRESS INTUBATION->MINVOL INTUBATION->SHUNT
In [6]:
print(bn2.names())
['PAP', 'VENTALV', 'TPR', 'HR', 'ARTCO2', 'KINKEDTUBE', 'PRESS', 'HREKG', 'LVEDVOLUME', 'CATECHOL', 'VENTMACH', 'BP', 'PCWP', 'LVFAILURE', 'HRSAT', 'DISCONNECT', 'ERRCAUTER', 'ERRLOWOUTPUT', 'MINVOL', 'SAO2', 'STROKEVOLUME', 'HISTORY', 'CO', 'CVP', 'SHUNT', 'VENTLUNG', 'FIO2', 'PULMEMBOLUS', 'PVSAT', 'HRBP', 'VENTTUBE', 'INSUFFANESTH', 'HYPOVOLEMIA', 'EXPCO2', 'ANAPHYLAXIS', 'MINVOLSET', 'INTUBATION']
In [7]:
gnb.showInference(bn2,evs={},size="12")
structs Inference in  13.27ms PAP ERRCAUTER PAP->ERRCAUTER VENTALV ARTCO2 VENTALV->ARTCO2 PVSAT VENTALV->PVSAT INTUBATION VENTALV->INTUBATION TPR BP TPR->BP ANAPHYLAXIS TPR->ANAPHYLAXIS HR CATECHOL HR->CATECHOL HR->ERRCAUTER ERRLOWOUTPUT HR->ERRLOWOUTPUT CO HR->CO KINKEDTUBE PRESS KINKEDTUBE->PRESS HREKG HREKG->ERRCAUTER HRBP HREKG->HRBP LVEDVOLUME PCWP LVEDVOLUME->PCWP LVFAILURE LVEDVOLUME->LVFAILURE CVP LVEDVOLUME->CVP VENTMACH VENTMACH->CATECHOL VENTTUBE VENTMACH->VENTTUBE VENTMACH->INTUBATION LVFAILURE->ERRLOWOUTPUT HISTORY LVFAILURE->HISTORY HRSAT HRSAT->HR HRSAT->HREKG HRSAT->ERRCAUTER HRSAT->HRBP DISCONNECT DISCONNECT->VENTTUBE MINVOL SAO2 SAO2->KINKEDTUBE SAO2->CATECHOL SAO2->HRSAT STROKEVOLUME STROKEVOLUME->LVFAILURE STROKEVOLUME->CO HYPOVOLEMIA STROKEVOLUME->HYPOVOLEMIA CO->BP SHUNT SHUNT->SAO2 VENTLUNG VENTLUNG->VENTALV VENTLUNG->ARTCO2 VENTLUNG->KINKEDTUBE VENTLUNG->MINVOL VENTLUNG->INTUBATION FIO2 FIO2->KINKEDTUBE FIO2->PVSAT PULMEMBOLUS PULMEMBOLUS->PAP PULMEMBOLUS->SHUNT PVSAT->SAO2 HRBP->HR HRBP->ERRLOWOUTPUT VENTTUBE->KINKEDTUBE VENTTUBE->PRESS VENTTUBE->ERRLOWOUTPUT VENTTUBE->VENTLUNG EXPCO2 VENTTUBE->EXPCO2 INSUFFANESTH INSUFFANESTH->CATECHOL HYPOVOLEMIA->LVEDVOLUME EXPCO2->VENTALV EXPCO2->ARTCO2 EXPCO2->MINVOL EXPCO2->VENTLUNG ANAPHYLAXIS->PRESS MINVOLSET </