SHD#
- class pgmpy.metrics.SHD[source]#
Bases:
_BaseSupervisedMetricComputes the Structural Hamming Distance between true_causal_graph and est_causal_graph.
SHD is defined as total number of basic operations: adding edges, removing edges, and reversing edges required to transform one graph to the other. It is a symmetrical measure.
The code first accounts for edges that need to be deleted (from true_model), added (to true_model) and finally edges that need to be reversed. All operations count as 1.
Examples
>>> from pgmpy.metrics import SHD >>> from pgmpy.base import DAG >>> dag1 = DAG([(1, 2), (2, 3)]) >>> dag2 = DAG([(2, 1), (2, 3)]) >>> shd = SHD() >>> shd(true_causal_graph=dag1, est_causal_graph=dag2) 1