classification/tree_explainer.py
def _inspect_tree(self) -> Tuple[Dict[int, List[int]], Dict[int, List[int]]]:
        """
        Go through the tree to get the parents of the leaves.

        :return:
        - Dict[leaf_id, List[node_ids]] leaf to parents. Parents are sorted leaf to root
        - Dict[target_id, List[leaf_ids]] target id (majority class) to corresponding leaves
        """
        tree = self.model.tree_
        parents = dict()
        value_leaves = defaultdict(list)
        leaves = list()

        def recurse(node: int, depth: int, parent: int):
            parents[node] = [parent, *parents.get(parent, [])]
            if tree.children_left[node] != tree.children_right[node]:
                recurse(tree.children_left[node], depth + 1, node)
                recurse(tree.children_right[node], depth + 1, node)
            else:
                val = tree.value[node][0].argmax()
                value_leaves[val].append(node)
                leaves.append(node)

        recurse(0, 0, None)

        parents = {k: v[:-1] for k, v in parents.items() if k in leaves}

        return parents, value_leaves

        Go through the tree to get the parents of the leaves.

        :return:
        - Dict[leaf_id, List[node_ids]] leaf to parents. Parents are sorted leaf to root
        - Dict[target_id, List[leaf_ids]] target id (majority class) to corresponding leaves
        
Go through the tree to get the parents of the leaves.
Go through the tree to get the parents of the leaves .
def _inspect_tree(self) -> Tuple[Dict[int, List[int]], Dict[int, List[int]]]:
        tree = self.model.tree_
        parents = dict()
        value_leaves = defaultdict(list)
        leaves = list()
        def recurse(node: int, depth: int, parent: int):
            parents[node] = [parent, *parents.get(parent, [])]
            if tree.children_left[node] != tree.children_right[node]:
                recurse(tree.children_left[node], depth + 1, node)
                recurse(tree.children_right[node], depth + 1, node)
            else:
                val = tree.value[node][0].argmax()
                value_leaves[val].append(node)
                leaves.append(node)
        recurse(0, 0, None)
        parents = {k: v[:-1] for k, v in parents.items() if k in leaves}
        return parents, value_leaves
def _inspect_tree ( self ) -> Tuple [ Dict [ int , List [ int ] ] , Dict [ int , List [ int ] ] ] : tree = self . model . tree_ parents = dict ( ) value_leaves = defaultdict ( list ) leaves = list ( ) def recurse ( node : int , depth : int , parent : int ) : parents [ node ] = [ parent , * parents . get ( parent , [ ] ) ] if tree . children_left [ node ] != tree . children_right [ node ] : recurse ( tree . children_left [ node ] , depth + 1 , node ) recurse ( tree . children_right [ node ] , depth + 1 , node ) else : val = tree . value [ node ] [ 0 ] . argmax ( ) value_leaves [ val ] . append ( node ) leaves . append ( node ) recurse ( 0 , 0 , None ) parents = { k : v [ : - 1 ] for k , v in parents . items ( ) if k in leaves } return parents , value_leaves
Go through the tree to get the parents of the leaves.
Go through the tree to get the parents of the leaves .
"""
        Go through the tree to get the parents of the leaves.

        :return:
        - Dict[leaf_id, List[node_ids]] leaf to parents. Parents are sorted leaf to root
        - Dict[target_id, List[leaf_ids]] target id (majority class) to corresponding leaves
        """
Dict[leaf_id, List[node_ids]] leaf to parents. Parents are sorted leaf to root
Dict[target_id, List[leaf_ids]] target id (majority class) to corresponding leaves
Dict [ leaf_id List [ node_ids ]] leaf to parents . Parents are sorted leaf to root Dict [ target_id List [ leaf_ids ]] target id ( majority class ) to corresponding leaves
self