Python package for Causal Discovery by learning the graphical structure of Bayesian networks. Structure Learning, Parameter Learning, Inferences, Sampling methods.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[87], line 2
1 # Make the DAG
----> 2 DAG = bn.make_DAG(DAG, CPD=[cpd_A, cpd_B, cpd_C, cpd_D], checkmodel=True)
File [~/anaconda3/envs/bnlearn/lib/python3.10/site-packages/bnlearn/bnlearn.py:158](https://file+.vscode-resource.vscode-cdn.net/home/suciokhan/rca/~/anaconda3/envs/bnlearn/lib/python3.10/site-packages/bnlearn/bnlearn.py:158), in make_DAG(DAG, CPD, methodtype, checkmodel, verbose)
156 # Check model
157 if checkmodel:
--> 158 check_model(DAG, verbose=verbose)
160 # Create adjacency matrix from DAG
161 out = {}
File [~/anaconda3/envs/bnlearn/lib/python3.10/site-packages/bnlearn/bnlearn.py:281](https://file+.vscode-resource.vscode-cdn.net/home/suciokhan/rca/~/anaconda3/envs/bnlearn/lib/python3.10/site-packages/bnlearn/bnlearn.py:281), in check_model(DAG, verbose)
279 if not np.all(cpd.values.astype(Decimal).sum(axis=0)==1):
280 if verbose>=3: print('[bnlearn] >CPD [%s] does not add up to 1 but is: %s' %(cpd.variable, cpd.values.sum(axis=0)))
--> 281 if verbose>=3: print('[bnlearn] >Check whether CPDs associated with the nodes are consistent: %s' %(DAG.check_model()))
282 else:
283 if verbose>=2: print('[bnlearn] >No model found containing CPDs.')
File [~/anaconda3/envs/bnlearn/lib/python3.10/site-packages/pgmpy/models/BayesianNetwork.py:438](https://file+.vscode-resource.vscode-cdn.net/home/suciokhan/rca/~/anaconda3/envs/bnlearn/lib/python3.10/site-packages/pgmpy/models/BayesianNetwork.py:438), in BayesianNetwork.check_model(self)
436 # Check if the evidence cardinality specified is same as parent's cardinality
437 if parent_cpd.cardinality[0] != cpd.cardinality[1 + index]:
--> 438 raise ValueError(
439 f"The cardinality of {node} doesn't match in it's child nodes."
440 )
441 # Check if the state_names are the same in parent and child CPDs.
442 if parent_cpd.state_names[node] != cpd.state_names[node]:
ValueError: The cardinality of A doesn't match in it's child nodes.
Please review the code in the example on the website and fix as needed.
In the
Naive Bayes
example shown on this page: https://erdogant.github.io/bnlearn/pages/html/Structure%20learning.htmlI receive an error when executing the following line of code, which was copied + pasted from the example:
DAG = bn.make_DAG(DAG, CPD=[cpd_A, cpd_B, cpd_C, cpd_D], checkmodel=True)
I created the cpd objects via copy/pasting as well; as follows:
The error generated is:
Please review the code in the example on the website and fix as needed.