class_docstr: Interpretable Model Differencing to explain the similarities and differences between two classifiers.
  Provides access to :class:`aix360.algorithms.imd.jst.JointSurrogateTree`, a novel data structure to
  compactly represent the differences between the models in terms of rules, and also provides a way to
  visualize the joint surrogate tree structure.
  
  References:
      .. [#UAI2023] `S. Haldar, D. Saha, D. Wei, R. Nair, E. M. Daly, "Interpretable Differencing of Machine Learning
          Models." Uncertainty in Artificial Intelligence (UAI), 2023.`
class_docstr_tok: ["Interpretable","Model","Differencing","to","explain","the","similarities","and","differences","between","two","classifiers",".","Provides","access","to",":","class",":","`","aix360.algorithms.imd.jst.JointSurrogateTree","`",",","a","novel","data","structure","to","compactly","represent","the","differences","between","the","models","in","terms","of","rules",",","and","also","provides","a","way","to","visualize","the","joint","surrogate","tree","structure",".","References",":","..","[","#","UAI2023","]","`","S.","Haldar",",","D.","Saha",",","D.","Wei",",","R.","Nair",",","E.","M.","Daly",",","``","Interpretable","Differencing","of","Machine","Learning","Models",".","''","Uncertainty","in","Artificial","Intelligence","(","UAI",")",",","2023.","`"]
docstr: take x_test and check the precision and recall
  precision =
     number of actual diff samples inside the diffregion /
     number of test samples inside the diffregion
  recall = diff samples inside the region / total number of diff samples
  
  
  Args:
      x_test: test data (only x) to compute diff-based metrics
      name: string (`train` or `test`)
  
  Returns:
      a dictionary having `precision`, `recall`, `num-rules`, and `num-unique-preds` values
      as obtained from the diff-rules extracted from the jst.
docstr_tok: ["take","x_test","and","check","the","precision","and","recall","precision","=","number","of","actual","diff","samples","inside","the","diffregion","\/","number","of","test","samples","inside","the","diffregion","recall","=","diff","samples","inside","the","region","\/","total","number","of","diff","samples","Args",":","x_test",":","test","data","(","only","x",")","to","compute","diff-based","metrics","name",":","string","(","`","train","`","or","`","test","`",")","Returns",":","a","dictionary","having","`","precision","`",",","`","recall","`",",","`","num-rules","`",",","and","`","num-unique-preds","`","values","as","obtained","from","the","diff-rules","extracted","from","the","jst","."]
code: def metrics(
      self, x_test: pd.DataFrame, y_test1, y_test2, name="test"
  ):
      """
      take x_test and check the precision and recall
      precision =
         number of actual diff samples inside the diffregion /
         number of test samples inside the diffregion
      recall = diff samples inside the region / total number of diff samples
  
  
      Args:
          x_test: test data (only x) to compute diff-based metrics
          name: string (`train` or `test`)
  
      Returns:
          a dictionary having `precision`, `recall`, `num-rules`, and `num-unique-preds` values
          as obtained from the diff-rules extracted from the jst.
      """
  
      if self.jst is None:
          print("jst not fitted yet, please call .fit method first!")
          return {}
  
      metrics = {}
      # y_test1 = self.model1.predict(x_test)
      # y_test2 = self.model2.predict(x_test)
      diff_samples = y_test1 != y_test2
      total_number_diff_samples = np.sum(diff_samples)
      metrics["diffs"] = total_number_diff_samples
      metrics["samples"] = len(x_test)
  
      inregiondiff = self.inregion(
          self.diffregions, x_test[diff_samples].to_numpy()
      )
      diff_samples_inside_diff_region = np.sum(inregiondiff)
      inregion = self.inregion(self.diffregions, x_test.to_numpy())
      samples_in_region = np.sum(inregion)
  
      metrics[name + "-precision"] = round(
          diff_samples_inside_diff_region / samples_in_region, 6
      )
      metrics[name + "-recall"] = round(
          diff_samples_inside_diff_region / total_number_diff_samples, 6
      )
      metrics["num-rules"] = len(self.diffregions)
  
      preds = []
      for rule in self.diffrules:
          preds += rule.predicates
      preds = set(preds)
      metrics["num-unique-preds"] = len(preds)
      return metrics
  
file_path: AIX360/aix360/algorithms/imd/imd.py
imports: from ..dise import DISExplainer
  import numpy
  import pandas
  from aix360.algorithms.imd.utils import _parse_feature_names
  from aix360.algorithms.imd.jst import JointSurrogateTree
  from aix360.algorithms.imd.rule import Rule
label_desc: Use image node_id 7 for calling the IMDExplainer obj's underlying member method code with example usage: obj.metrics(x_test, y_test1, y_test2, name) and returns: metrics, dict