classification/tree_explainer.py
def print_path(self, sample: DataFrame, parents: Dict[int, List[int]] = None):
        """
        Prints the complete path that led to the classification of the sample.
        """
        tree = self.model.tree_
        if parents is None:
            parents, _ = self._inspect_tree()
        leaf = self.model.apply(sample)[0]
        node_ids = parents[leaf]
        predicted = self.model.predict(sample)[0]
        decisions = self._convert_to_decisions(node_ids, leaf, sample)

        print("Rules that predict sample {}:".format(sample.index[0]))
        for node_id, decision in zip(reversed(node_ids), reversed(decisions)):
            print("Node {}: {}".format(node_id, decision))

        print("Therefore, the expected result is:", self.target_names[predicted])
        print("The impurity at this leaf, {}, is: {}".format(leaf, tree.impurity[leaf]))
        print("Distribution at leaf: ", {k: v for k, v in
                                         zip(self.target_names, tree.value[leaf][0])})

        Prints the complete path that led to the classification of the sample.
        
Prints the complete path that led to the classification of the sample.
Prints the complete path that led to the classification of the sample .
def print_path(self, sample: DataFrame, parents: Dict[int, List[int]] = None):
        tree = self.model.tree_
        if parents is None:
            parents, _ = self._inspect_tree()
        leaf = self.model.apply(sample)[0]
        node_ids = parents[leaf]
        predicted = self.model.predict(sample)[0]
        decisions = self._convert_to_decisions(node_ids, leaf, sample)
        print("Rules that predict sample {}:".format(sample.index[0]))
        for node_id, decision in zip(reversed(node_ids), reversed(decisions)):
            print("Node {}: {}".format(node_id, decision))
        print("Therefore, the expected result is:", self.target_names[predicted])
        print("The impurity at this leaf, {}, is: {}".format(leaf, tree.impurity[leaf]))
        print("Distribution at leaf: ", {k: v for k, v in
                                         zip(self.target_names, tree.value[leaf][0])})
def print_path ( self , sample : DataFrame , parents : Dict [ int , List [ int ] ] = None ) : tree = self . model . tree_ if parents is None : parents , _ = self . _inspect_tree ( ) leaf = self . model . apply ( sample ) [ 0 ] node_ids = parents [ leaf ] predicted = self . model . predict ( sample ) [ 0 ] decisions = self . _convert_to_decisions ( node_ids , leaf , sample ) print ( "Rules that predict sample {}:" . format ( sample . index [ 0 ] ) ) for node_id , decision in zip ( reversed ( node_ids ) , reversed ( decisions ) ) : print ( "Node {}: {}" . format ( node_id , decision ) ) print ( "Therefore, the expected result is:" , self . target_names [ predicted ] ) print ( "The impurity at this leaf, {}, is: {}" . format ( leaf , tree . impurity [ leaf ] ) ) print ( "Distribution at leaf: " , { k : v for k , v in zip ( self . target_names , tree . value [ leaf ] [ 0 ] ) } )
Prints the complete path that led to the classification of the sample.
Prints the complete path that led to the classification of the sample .
"""
        Prints the complete path that led to the classification of the sample.
        """
self
sample
DataFrame
parents
Dict[int, List[int]]