causaldag.classes.dag.DAG.confusion_matrix_skeleton

DAG.confusion_matrix_skeleton(other)[source]

Return the “confusion matrix” associated with estimating the skeleton of other instead of the skeleton of this DAG.

Parameters:other – The DAG against which to compare.
Returns:Dictionary of results
  • false_positives:
    the edges in the skeleton of other which are not in the skeleton of this DAG.
  • false_negatives:
    the edges in the skeleton of this graph which are not in the skeleton of other.
  • true_positives:
    the edges in the skeleton of other which are acutally in the skeleton of this DAG.
  • num_false_positives:
    the total number of false_positives
  • num_false_negatives:
    the total number of false_negatives
  • num_true_positives:
    the total number of true_positives
  • num_true_negatives:
    the total number of missing edges in the skeleton of other which are actually missing in this DAG.
  • fpr:
    the false positive rate, i.e., num_false_positives/(num_false_positives+num_true_negatives). If this DAG is fully connected, defaults to 0.
  • tpr:
    the true positive rate, i.e., num_true_positives/(num_true_positives+num_false_negatives). If this DAG is empty, defaults to 1.
  • precision:
    the precision, i.e., num_true_positives/(num_true_positives+num_false_positives). If other is empty, defaults to 1.
Return type:dict

Examples

>>> import causaldag as cd
>>> d1 = cd.DAG(arcs={(0, 1), (1, 2)})
>>> d2 = cd.DAG(arcs={(0, 1), (2, 1)})
>>> cm = d1.confusion_matrix_skeleton(d2)
>>> cm["tpr"]
1.0
>>> d3 = cd.DAG(arcs={(0, 1), (0, 2)})
>>> cm = d2.confusion_matrix_skeleton(d3)
>>> cm["true_positives"]
{frozenset({0, 1})}
>>> cm["false_positives"]
{frozenset({0, 2})},
>>> cm["false_negatives"]
{frozenset({1, 2})}