code: def decision_tree_to_rules(dt, feature_names, return_type="dict"):
      """
      utility to get rules from a scikit-learn decision tree model.
      Args:
          dt: scikit-learn `DecisionTreeClassifier` fitted model
          feature_names: list
          return_type: list/dictionary of rules
  
      Returns:
          list/dictionary of rules based on `return_type`
      """
  
      n_nodes = dt.tree_.node_count
      children_left = dt.tree_.children_left
      children_right = dt.tree_.children_right
      feature = dt.tree_.feature
      threshold = dt.tree_.threshold
      value = dt.tree_.value
  
      rules = dict()
  
      def dfs(node_id, rule):
          is_split_node = (
              children_left[node_id] != children_right[node_id]
          )
          if is_split_node:
              f = feature[node_id]
              t = threshold[node_id]
              name = feature_names[f]
              dfs(children_left[node_id], rule + [(name, "<=", t)])
              dfs(children_right[node_id], rule + [(name, ">", t)])
          else:
              class_distribution = value[node_id]
              label = np.argmax(
                  value[node_id][0]
              )  # take majority class' label
              rule = Rule(node_id, rule, label)
              rules[node_id] = rule
              # rules.append(rule)
  
      dfs(0, rule=[])
      if return_type == "dict":
          return rules
      return [item for (key, item) in rules.items()]
  
file_path: AIX360/aix360/algorithms/imd/utils.py
imports: import numpy
  import pandas
  import networkx
  from collections import defaultdict
  from aix360.algorithms.imd.rule import Rule
label_desc: Use image node_id 1 for calling a global function with example usage: decision_tree_to_rules(dt, feature_names, return_type) and returns: unknown, rules