Learning essential graphs
![]() | ![]() |
from pylab import *
import pyagrum as gumimport pyagrum.lib.notebook as gnbCompare learning algorithms
Section titled “Compare learning algorithms”Essentially MIIC computes the essential graph (CPDAG) from data. Essential graphs are PDAGs (Partially Directed Acyclic Graphs).
learner = gum.BNLearner("res/sample_asia.csv")learner.useMIIC()learner.useNMLCorrection()print(learner)Filename : res/sample_asia.csvSize : (50000,8)Variables : visit_to_Asia[2], lung_cancer[2], tuberculosis[2], bronchitis[2], positive_XraY[2], smoking[2], tuberculos_or_cancer[2], dyspnoea[2]Induced types : TrueMissing values : FalseAlgorithm : MIICCorrection : NMLPrior : -gemiic = learner.learnEssentialGraph()gnb.show(gemiic)For the others methods, it is possible to obtain the essential graph from the learned BN.
learner = gum.BNLearner("res/sample_asia.csv")learner.useGreedyHillClimbing()bnHC = learner.learnBN()print(learner)geHC = gum.EssentialGraph(bnHC)geHCgnb.sideBySide(bnHC, geHC)Filename : res/sample_asia.csvSize : (50000,8)Variables : visit_to_Asia[2], lung_cancer[2], tuberculosis[2], bronchitis[2], positive_XraY[2], smoking[2], tuberculos_or_cancer[2], dyspnoea[2]Induced types : TrueMissing values : FalseAlgorithm : Greedy Hill ClimbingScore : BDeuPrior : -learner = gum.BNLearner("res/sample_asia.csv")learner.useLocalSearchWithTabuList()print(learner)bnTL = learner.learnBN()geTL = gum.EssentialGraph(bnTL)geTLgnb.sideBySide(bnTL, geTL)Filename : res/sample_asia.csvSize : (50000,8)Variables : visit_to_Asia[2], lung_cancer[2], tuberculosis[2], bronchitis[2], positive_XraY[2], smoking[2], tuberculos_or_cancer[2], dyspnoea[2]Induced types : TrueMissing values : FalseAlgorithm : Local Search with Tabu ListTabu list size : 2Score : BDeuPrior : -Hence we can compare the 4 algorithms.
( gnb.flow.clear() .add(gemiic, "Essential graph from miic") .add(bnHC, "BayesNet from GHC") .add(geHC, "Essential graph from GHC") .add(bnTL, "BayesNet from TabuList") .add(geTL, "Essential graph from TabuList") .display())
