code: def _mean_depth_sklearn_tree(tree_, X, feature_costs):
      n_nodes = tree_.node_count
      children_left = tree_.children_left
      children_right = tree_.children_right
  
      # things to compute
      _node_depth = np.zeros(shape=n_nodes, dtype=np.int64)
      _is_leaves = np.zeros(shape=n_nodes, dtype=bool)
      _cum_costs = np.zeros(shape=n_nodes, dtype=np.float64)
  
      # start with the root node id (0) and its depth (0) and its cost (0)
      stack = [(0, 0, 0)]
      while len(stack) > 0:
          node_id, depth, cost = stack.pop()
          _node_depth[node_id] = depth
          _cum_costs[node_id] = cost
  
          is_split_node = (
              children_left[node_id] != children_right[node_id]
          )
  
          cost += feature_costs[tree_.feature[node_id]]
          if is_split_node:
              stack.append((children_left[node_id], depth + 1, cost))
              stack.append((children_right[node_id], depth + 1, cost))
          else:
              _is_leaves[node_id] = True
  
      # iterate over leaves and calculate the number of samples in each of them
      n_samples = tree_.n_node_samples
      leaf_samples = n_samples[_is_leaves].astype(np.float64)
      depths = (
          _cum_costs[_is_leaves] * leaf_samples / np.sum(leaf_samples)
      )
      return np.sum(depths)
  
file_path: imodels/imodels/util/tree.py
imports: from sklearn import datasets
  from sklearn.tree import DecisionTreeRegressor
  import numpy
  from sklearn.tree._tree import Tree
  from imodels.tree.custom_greedy_tree import CustomDecisionTreeClassifier
label_desc: Use image node_id 5 for calling a global function with example usage: _mean_depth_sklearn_tree(tree_, X, feature_costs) and returns: np