Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  LearningAndEssentialGraphs 
pyAgrum 0.18.0   
Zipped notebooks   
generation: 2020-06-11 14:09  

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 dyspnoea 1 tuberculos_or_cancer 1->0 5 positive_XraY 1->5 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 7 smoking 3->7 4->1 6 bronchitis 6->0 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 dyspnoea 1 tuberculos_or_cancer 1->0 5 positive_XraY 1->5 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 7 smoking 3->7 4->1 6 bronchitis 6->0 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 dyspnoea dyspnoea tuberculos_or_cancer tuberculos_or_cancer tuberculos_or_cancer->dyspnoea positive_XraY positive_XraY tuberculos_or_cancer->positive_XraY visit_to_Asia visit_to_Asia lung_cancer lung_cancer lung_cancer->tuberculos_or_cancer smoking smoking lung_cancer->smoking tuberculosis tuberculosis tuberculosis->tuberculos_or_cancer tuberculosis->visit_to_Asia bronchitis bronchitis bronchitis->dyspnoea smoking->bronchitis
no_name 0 dyspnoea 1 tuberculos_or_cancer 1->0 5 positive_XraY 1->5 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 7 smoking 3->7 4->1 6 bronchitis 6->0 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 dyspnoea dyspnoea tuberculos_or_cancer tuberculos_or_cancer tuberculos_or_cancer->dyspnoea visit_to_Asia visit_to_Asia tuberculosis tuberculosis visit_to_Asia->tuberculosis lung_cancer lung_cancer lung_cancer->tuberculos_or_cancer positive_XraY positive_XraY lung_cancer->positive_XraY smoking smoking lung_cancer->smoking tuberculosis->tuberculos_or_cancer tuberculosis->positive_XraY bronchitis bronchitis bronchitis->dyspnoea smoking->bronchitis
no_name 0 dyspnoea 1 tuberculos_or_cancer 1->0 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 5 positive_XraY 3->5 7 smoking 3->7 4->1 4->5 6 bronchitis 6->0 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 dyspnoea 1 tuberculos_or_cancer 1->0 5 positive_XraY 1->5 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 7 smoking 3->7 4->1 6 bronchitis 6->0 6->7
no_name 0 dyspnoea 1 tuberculos_or_cancer 1->0 5 positive_XraY 1->5 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 7 smoking 3->7 4->1 6 bronchitis 6->0 6->7
G dyspnoea dyspnoea tuberculos_or_cancer tuberculos_or_cancer tuberculos_or_cancer->dyspnoea positive_XraY positive_XraY tuberculos_or_cancer->positive_XraY visit_to_Asia visit_to_Asia lung_cancer lung_cancer lung_cancer->tuberculos_or_cancer smoking smoking lung_cancer->smoking tuberculosis tuberculosis tuberculosis->tuberculos_or_cancer tuberculosis->visit_to_Asia bronchitis bronchitis bronchitis->dyspnoea smoking->bronchitis
no_name 0 dyspnoea 1 tuberculos_or_cancer 1->0 5 positive_XraY 1->5 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 7 smoking 3->7 4->1 6 bronchitis 6->0 6->7
G dyspnoea dyspnoea tuberculos_or_cancer tuberculos_or_cancer tuberculos_or_cancer->dyspnoea visit_to_Asia visit_to_Asia tuberculosis tuberculosis visit_to_Asia->tuberculosis lung_cancer lung_cancer lung_cancer->tuberculos_or_cancer positive_XraY positive_XraY lung_cancer->positive_XraY smoking smoking lung_cancer->smoking tuberculosis->tuberculos_or_cancer tuberculosis->positive_XraY bronchitis bronchitis bronchitis->dyspnoea smoking->bronchitis
no_name 0 dyspnoea 1 tuberculos_or_cancer 1->0 2 visit_to_Asia 4 tuberculosis 2->4 3 lung_cancer 3->1 5 positive_XraY 3->5 7 smoking 3->7 4->1 4->5 6 bronchitis 6->0 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 [ ]: