class_docstr: In sklearn the tree of the Isolation Forest does not calculated in a good way.
class_docstr_tok: ["In","sklearn","the","tree","of","the","Isolation","Forest","does","not","calculated","in","a","good","way","."]
code: def __init__(
      self,
      tree,
      tree_features,
      normalize=False,
      scaling=1.0,
      data=None,
      data_missing=None,
  ):
      super().__init__(tree, normalize, scaling, data, data_missing)
      if safe_isinstance(tree, "sklearn.tree._tree.Tree"):
          from sklearn.ensemble._iforest import (
              _average_path_length,
          )
  
          def _recalculate_value(tree, i, level):
              if (
                  tree.children_left[i] == -1
                  and tree.children_right[i] == -1
              ):
                  value = (
                      level
                      + _average_path_length(
                          np.array([tree.n_node_samples[i]])
                      )[0]
                  )
                  self.values[i, 0] = value
                  return value * tree.n_node_samples[i]
              else:
                  value_left = _recalculate_value(
                      tree, tree.children_left[i], level + 1
                  )
                  value_right = _recalculate_value(
                      tree, tree.children_right[i], level + 1
                  )
                  self.values[i, 0] = (
                      value_left + value_right
                  ) / tree.n_node_samples[i]
                  return value_left + value_right
  
          _recalculate_value(tree, 0, 0)
          if normalize:
              self.values = (self.values.T / self.values.sum(1)).T
          self.values = self.values * scaling
          # re-number the features if each tree gets a different set of features
          self.features = np.where(
              self.features >= 0,
              tree_features[self.features],
              self.features,
          )
  
imports: import json
  import os
  import struct
  import time
  import warnings
  import numpy
  import pandas
  import scipy.sparse
  import scipy.special
  from packaging import version
  from ..None import maskers
  from .._explanation import Explanation
  from ..utils import assert_import, record_import_error, safe_isinstance
  from ..utils._exceptions import DimensionError, ExplainerError, InvalidFeaturePerturbationError, InvalidMaskerError, InvalidModelError
  from ..utils._legacy import DenseData
  from ._explainer import Explainer
label_desc: Use image node_id 1 to create a new IsoTree object from inherited base classes: SingleTree with example: obj = IsoTree(tree, tree_features, normalize, scaling, data, data_missing)