code: def compute_rule_metrics(
      ruleset: DnfRuleSet, X: pd.DataFrame, y: pd.Series
  ) -> List[RuleContributionMetrics]:
      """
      Compute individual rule-level contribution to coverage and redundancy.
      See https://ibm.ent.box.com/file/888961054325?sb=/activity/annotations/956283151925 for more context.
  
      @param X: features
      @param y: labels
      @return: a dict mapping the string representation of conjunctions to a dict containing the contribution metrics
      """
      then_part = ruleset.then_part
      res = []
      for conjunction in ruleset.conjunctions:
          complement = deepcopy(ruleset)
          complement.remove_conjunction(conjunction)
          y_pred_compl = batch_evaluate(complement, X)
          (
              tp_compl,
              tn_compl,
              fp_compl,
              fn_compl,
          ) = get_preaggregated_confusion_matrix(
              y_pred_compl, y, then_part
          )
          y_pred_conj = batch_evaluate(conjunction, X)
          (
              tp_conj,
              tn_conj,
              fp_conj,
              fn_conj,
          ) = get_preaggregated_confusion_matrix(
              y_pred_conj, y, then_part
          )
          laplace_estimate = (len(tp_conj) + 1) / (
              len(tp_conj) + len(fp_conj) + 2
          )
  
          tp_common = len(set(tp_conj).intersection(set(tp_compl)))
          tp_unique = len(set(tp_conj).difference(set(tp_compl)))
          fp_common = len(set(fp_conj).intersection(set(fp_compl)))
          fp_unique = len(set(fp_conj).difference(set(fp_compl)))
          n_correct = len(tn_conj) + len(tp_conj)
          n_records = X.shape[0]
          res.append(
              RuleContributionMetrics(
                  conjunction,
                  tp_common,
                  tp_unique,
                  fp_common,
                  fp_unique,
                  n_correct,
                  n_records,
                  laplace_estimate,
              )
          )
      return res
  
file_path: AIX360/aix360/algorithms/rule_induction/trxf/metrics.py
imports: from collections import namedtuple
  from copy import deepcopy
  from typing import List
  import numpy
  import pandas
  from sklearn.metrics import confusion_matrix
  from aix360.algorithms.rule_induction.trxf.core.dnf_ruleset import DnfRuleSet
  from aix360.algorithms.rule_induction.trxf.core.utils import batch_evaluate
label_desc: Use image node_id 2 for calling a global function with example usage: compute_rule_metrics(ruleset, X, y) and returns: res