code: def _extract_rules(tree, feature_names):
      left = tree.tree_.children_left
      right = tree.tree_.children_right
      features = [feature_names[i] for i in tree.tree_.feature]
  
      # get ids of child nodes
      idx = np.argwhere(left == -1)[:, 0]
  
      def _recurse(left, right, child, lineage=None):
          if lineage is None:
              lineage = []
          if child in left:
              parent = np.where(left == child)[0].item()
              suffix = "_neg"
          else:
              parent = np.where(right == child)[0].item()
              suffix = ""
          lineage.append((features[parent].strip() + suffix))
  
          if parent == 0:
              lineage.reverse()
              return lineage
          else:
              return _recurse(left, right, parent, lineage)
  
      rules = []
      for child in idx:
          rule = []
          for node in _recurse(left, right, child):
              rule.append(node)
          rules.append(rule)
      return rules
  
imports: import itertools
  import operator
  import os
  import warnings
  from os.path import join
  from bisect import bisect_left
  from collections import defaultdict
  from copy import deepcopy
  from itertools import combinations
  from random import sample
  import numpy
  import pandas
  from mlxtend.frequent_patterns import fpgrowth
  from numpy.random import random
  from pandas import read_csv
  from scipy.sparse import csc_matrix
  from sklearn.base import BaseEstimator, ClassifierMixin
  from sklearn.ensemble import RandomForestClassifier
  from sklearn.utils.multiclass import check_classification_targets
  from sklearn.utils.validation import check_X_y, check_is_fitted
  from imodels.rule_set.rule_set import RuleSet
  from imodels.util.arguments import check_fit_arguments
label_desc: Use image node_id 6 for calling a global function with example usage: _extract_rules(tree, feature_names) and returns: rules, lineage, _recurse