causaldag.classes.dag.DAG.confusion_matrix

DAG.confusion_matrix(other, rates_only=False)[source]

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

Parameters:
  • other – The DAG against which to compare.
  • rates_only – if True, the dictionary of results only contains the false positive rate, true positive rate, and precision.
Returns:

Dictionary of results

  • false_positive_arcs:
    the arcs in the CPDAG of other which are not arcs or edges in the CPDAG of this DAG.
  • false_positive_edges:
    the edges in the CPDAG of other which are not arcs or edges in the CPDAG of this DAG.
  • false_negative_arcs:
    the arcs in the CPDAG of this graph which are not arcs or edges in the CPDAG of other.
  • true_positive_arcs:
    the arcs in the CPDAG of other which are arcs in the CPDAG of this DAG.
  • reversed_arcs:
    the arcs in the CPDAG of other whose reversals are arcs in the CPDAG of this DAG.
  • mistaken_arcs_for_edges:
    the arcs in the CPDAG of other whose reversals are arcs in the CPDAG of this DAG.
  • false_negative_edges:
    the edges in the CPDAG of this DAG which are not arcs or edges in the CPDAG of other.
  • true_positive_edges:
    the edges in the CPDAG of other which are edges in the CPDAG of this DAG.
  • mistaken_edges_for_arcs:
    the edges in the CPDAG of other which are arcs in the CPDAG of this DAG.
  • num_false_positives:
    the total number of: false_positive_arcs, false_positive_edges
  • num_false_negatives:
    the total number of: false_negative_arcs, false_negative_edges, mistaken_arcs_for_edges, and reversed_arcs
  • num_true_positives:
    the total number of: true_positive_arcs, true_positive_edges, and mistaken_edges_for_arcs
  • num_true_negatives:
    the total number of missing arcs/edges in 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(d2)
>>> cm["mistaken_edges_for_arcs"]
{frozenset({0, 1}), frozenset({1, 2})},
>>> cm = d2.confusion_matrix(d1)
>>> cm["mistaken_arcs_for_edges"]
{(0, 1), (2, 1)}