Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  LearningAndEssentialGraphs 
pyAgrum 0.17.3   
Zipped notebooks   
generation: 2020-04-27 18:59  

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

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

import os

import pyAgrum as gum
import pyAgrum.lib.notebook as gnb

Compare learning algorithms

Essentially MIIC and 3off2 computes the essential graph (CPDAG) from data. Essential graphs are mixed graphs.

In [2]:
learner=gum.BNLearner(os.path.join("out","sample_asia.csv"))
learner.use3off2()
learner.useNML()
ge3off2=learner.learnMixedStructure()
ge3off2
Out[2]:
no_name 0 tuberculosis 3 visit_to_Asia 0->3 6 tuberculos_or_cancer 0->6 1 smoking 4 lung_cancer 1->4 5 bronchitis 1->5 2 dyspnoea 4->6 5->2 6->2 7 positive_XraY 6->7
In [3]:
learner=gum.BNLearner(os.path.join("out","sample_asia.csv"))
learner.useMIIC()
learner.useNML()
gemiic=learner.learnMixedStructure()
gemiic
Out[3]:
no_name 0 tuberculosis 3 visit_to_Asia 0->3 6 tuberculos_or_cancer 0->6 1 smoking 4 lung_cancer 1->4 5 bronchitis 1->5 2 dyspnoea 4->6 5->2 6->2 7 positive_XraY 6->7

For the others methods, it is possible to obtain the essential graph from the learned BN.

In [4]:
learner=gum.BNLearner(os.path.join("out","sample_asia.csv"))
learner.useGreedyHillClimbing()
bnHC=learner.learnBN()
geHC=gum.EssentialGraph(bnHC)
geHC
gnb.sideBySide(bnHC,geHC)
G tuberculosis tuberculosis visit_to_Asia visit_to_Asia tuberculosis->visit_to_Asia smoking smoking dyspnoea dyspnoea lung_cancer lung_cancer lung_cancer->tuberculosis lung_cancer->smoking bronchitis bronchitis bronchitis->smoking bronchitis->dyspnoea bronchitis->lung_cancer tuberculos_or_cancer tuberculos_or_cancer tuberculos_or_cancer->tuberculosis tuberculos_or_cancer->dyspnoea tuberculos_or_cancer->lung_cancer tuberculos_or_cancer->bronchitis positive_XraY positive_XraY tuberculos_or_cancer->positive_XraY
no_name 0 tuberculosis 3 visit_to_Asia 0->3 4 lung_cancer 0->4 6 tuberculos_or_cancer 0->6 1 smoking 1->4 5 bronchitis 1->5 2 dyspnoea 2->5 2->6 4->5 4->6 5->6 7 positive_XraY 6->7
In [5]:
learner=gum.BNLearner(os.path.join("out","sample_asia.csv"))
learner.useLocalSearchWithTabuList()
bnTL=learner.learnBN()
geTL=gum.EssentialGraph(bnTL)
geTL
gnb.sideBySide(bnTL,geTL)
G tuberculosis tuberculosis lung_cancer lung_cancer tuberculosis->lung_cancer tuberculos_or_cancer tuberculos_or_cancer tuberculosis->tuberculos_or_cancer positive_XraY positive_XraY tuberculosis->positive_XraY smoking smoking dyspnoea dyspnoea smoking->dyspnoea bronchitis bronchitis smoking->bronchitis visit_to_Asia visit_to_Asia visit_to_Asia->tuberculosis lung_cancer->smoking lung_cancer->tuberculos_or_cancer bronchitis->dyspnoea tuberculos_or_cancer->dyspnoea tuberculos_or_cancer->positive_XraY
no_name 0 tuberculosis 3 visit_to_Asia 0->3 4 lung_cancer 0->4 6 tuberculos_or_cancer 0->6 7 positive_XraY 0->7 1 smoking 2 dyspnoea 1->2 1->4 5 bronchitis 1->5 4->6 5->2 6->2 6->7

Hence we can compare the 4 algorithms.

In [6]:
gnb.sideBySide(ge3off2,gemiic,bnHC,geHC,bnTL,geTL,
               captions=["Essential graph from 3off2",
                        "Essential graph from miic",
                        "BayesNet from HC",
                        "Essential graph from HC",
                        "BayesNet form TabuList",
                        "Essential graph from TabuList"])
no_name 0 tuberculosis 3 visit_to_Asia 0->3 6 tuberculos_or_cancer 0->6 1 smoking 4 lung_cancer 1->4 5 bronchitis 1->5 2 dyspnoea 4->6 5->2 6->2 7 positive_XraY 6->7
no_name 0 tuberculosis 3 visit_to_Asia 0->3 6 tuberculos_or_cancer 0->6 1 smoking 4 lung_cancer 1->4 5 bronchitis 1->5 2 dyspnoea 4->6 5->2 6->2 7 positive_XraY 6->7
G tuberculosis tuberculosis visit_to_Asia visit_to_Asia tuberculosis->visit_to_Asia smoking smoking dyspnoea dyspnoea lung_cancer lung_cancer lung_cancer->tuberculosis lung_cancer->smoking bronchitis bronchitis bronchitis->smoking bronchitis->dyspnoea bronchitis->lung_cancer tuberculos_or_cancer tuberculos_or_cancer tuberculos_or_cancer->tuberculosis tuberculos_or_cancer->dyspnoea tuberculos_or_cancer->lung_cancer tuberculos_or_cancer->bronchitis positive_XraY positive_XraY tuberculos_or_cancer->positive_XraY
no_name 0 tuberculosis 3 visit_to_Asia 0->3 4 lung_cancer 0->4 6 tuberculos_or_cancer 0->6 1 smoking 1->4 5 bronchitis 1->5 2 dyspnoea 2->5 2->6 4->5 4->6 5->6 7 positive_XraY 6->7
G tuberculosis tuberculosis lung_cancer lung_cancer tuberculosis->lung_cancer tuberculos_or_cancer tuberculos_or_cancer tuberculosis->tuberculos_or_cancer positive_XraY positive_XraY tuberculosis->positive_XraY smoking smoking dyspnoea dyspnoea smoking->dyspnoea bronchitis bronchitis smoking->bronchitis visit_to_Asia visit_to_Asia visit_to_Asia->tuberculosis lung_cancer->smoking lung_cancer->tuberculos_or_cancer bronchitis->dyspnoea tuberculos_or_cancer->dyspnoea tuberculos_or_cancer->positive_XraY
no_name 0 tuberculosis 3 visit_to_Asia 0->3 4 lung_cancer 0->4 6 tuberculos_or_cancer 0->6 7 positive_XraY 0->7 1 smoking 2 dyspnoea 1->2 1->4 5 bronchitis 1->5 4->6 5->2 6->2 6->7
Essential graph from 3off2
Essential graph from miic
BayesNet from HC
Essential graph from HC
BayesNet form TabuList
Essential graph from TabuList
In [ ]: