Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  LearningAndEssentialGraphs 
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]:
%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 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 3 lung_cancer? 3->4 3->5 5->6 7 positive_XraY? 5->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 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 3 lung_cancer? 3->4 3->5 5->6 7 positive_XraY? 5->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 bronchitis? bronchitis? smoking? smoking? bronchitis?->smoking? dyspnoea? dyspnoea? bronchitis?->dyspnoea? tuberculosis? tuberculosis? tuberculosis?->bronchitis? visit_to_Asia? visit_to_Asia? tuberculosis?->visit_to_Asia? tuberculos_or_cancer? tuberculos_or_cancer? tuberculosis?->tuberculos_or_cancer? lung_cancer? lung_cancer? lung_cancer?->smoking? lung_cancer?->tuberculos_or_cancer? tuberculos_or_cancer?->bronchitis? tuberculos_or_cancer?->dyspnoea? positive_XraY? positive_XraY? tuberculos_or_cancer?->positive_XraY?
no_name 0 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 1->0 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 3 lung_cancer? 3->4 3->5 5->0 5->6 7 positive_XraY? 5->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 bronchitis? bronchitis? dyspnoea? dyspnoea? bronchitis?->dyspnoea? tuberculosis? tuberculosis? tuberculos_or_cancer? tuberculos_or_cancer? tuberculosis?->tuberculos_or_cancer? positive_XraY? positive_XraY? tuberculosis?->positive_XraY? visit_to_Asia? visit_to_Asia? visit_to_Asia?->tuberculosis? lung_cancer? lung_cancer? smoking? smoking? lung_cancer?->smoking? lung_cancer?->tuberculos_or_cancer? lung_cancer?->positive_XraY? smoking?->bronchitis? smoking?->dyspnoea? tuberculos_or_cancer?->dyspnoea?
no_name 0 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 7 positive_XraY? 1->7 3 lung_cancer? 3->4 3->5 3->7 4->6 5->6

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 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 3 lung_cancer? 3->4 3->5 5->6 7 positive_XraY? 5->7
no_name 0 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 3 lung_cancer? 3->4 3->5 5->6 7 positive_XraY? 5->7
G bronchitis? bronchitis? smoking? smoking? bronchitis?->smoking? dyspnoea? dyspnoea? bronchitis?->dyspnoea? tuberculosis? tuberculosis? tuberculosis?->bronchitis? visit_to_Asia? visit_to_Asia? tuberculosis?->visit_to_Asia? tuberculos_or_cancer? tuberculos_or_cancer? tuberculosis?->tuberculos_or_cancer? lung_cancer? lung_cancer? lung_cancer?->smoking? lung_cancer?->tuberculos_or_cancer? tuberculos_or_cancer?->bronchitis? tuberculos_or_cancer?->dyspnoea? positive_XraY? positive_XraY? tuberculos_or_cancer?->positive_XraY?
no_name 0 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 1->0 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 3 lung_cancer? 3->4 3->5 5->0 5->6 7 positive_XraY? 5->7
G bronchitis? bronchitis? dyspnoea? dyspnoea? bronchitis?->dyspnoea? tuberculosis? tuberculosis? tuberculos_or_cancer? tuberculos_or_cancer? tuberculosis?->tuberculos_or_cancer? positive_XraY? positive_XraY? tuberculosis?->positive_XraY? visit_to_Asia? visit_to_Asia? visit_to_Asia?->tuberculosis? lung_cancer? lung_cancer? smoking? smoking? lung_cancer?->smoking? lung_cancer?->tuberculos_or_cancer? lung_cancer?->positive_XraY? smoking?->bronchitis? smoking?->dyspnoea? tuberculos_or_cancer?->dyspnoea?
no_name 0 bronchitis? 4 smoking? 0->4 6 dyspnoea? 0->6 1 tuberculosis? 2 visit_to_Asia? 1->2 5 tuberculos_or_cancer? 1->5 7 positive_XraY? 1->7 3 lung_cancer? 3->4 3->5 3->7 4->6 5->6
Essential graph from 3off2
Essential graph from miic
BayesNet from HC
Essential graph from HC
BayesNet form TabuList
Essential graph from TabuList
In [ ]: