BNLearner.setPCAlpha
- BNLearner.setPCAlpha(alpha)
Set the significance threshold (α) used by the PC algorithm to decide whether two variables are conditionally independent.
An edge (X, Y) is removed from the skeleton when the p-value of the conditional independence test exceeds α. Smaller α removes more edges (sparser graphs); larger α keeps more edges.
- Parameters:
alpha (
float) – significance threshold in (0, 1). If it is never set, the learner usespyagrum.config['learning', 'alpha'](0.05) as it was when the learner was created.- Returns:
the BNLearner itself, to allow method chaining.
- Return type:
- Raises:
pyagrum.OperationNotAllowed – If the PC algorithm has not been selected (call
usePC()first).pyagrum.OutOfBounds – If alpha is not strictly between 0 and 1.
Example
import pyagrum as gum
with open("data.csv", "w") as f: # C is mostly "A or B"
f.write("A,B,C\n" + "0,0,0\n0,1,1\n1,0,1\n1,1,1\n" * 40 + "0,0,1\n0,1,0\n1,0,0\n1,1,0\n" * 5)
learner = gum.BNLearner("data.csv")
learner.usePC().setPCAlpha(1e-60) # a very small alpha: every edge is removed
pdag = learner.learnPDAG()
pdag.sizeArcs() + pdag.sizeEdges()
# 0
Class