def _delete_node(self, tree, node):
        """ Private function that eliminate node from tree.

        Parameters
        ----------

        tree : object

        node : int
            node to be eliminated from tree

        Returns
        -------

        pruned_tree : object
        """
        # Calculate gains
        temp_tree = copy.deepcopy(tree)

        def recourse(temp_tree_, del_node):
            if isinstance(temp_tree_, dict):
                if temp_tree_['split'] != -1:
                    if temp_tree_['node'] == del_node:
                        del temp_tree_['sr']
                        del temp_tree_['sl']
                        del temp_tree_['node']
                        temp_tree_['split'] = -1
                    else:
                        for k in ['sl', 'sr']:
                            recourse(temp_tree_[k], del_node)
            return None

        recourse(temp_tree, node)
        return temp_tree
def _delete_node ( self , tree , node ) : temp_tree = copy . deepcopy ( tree ) def recourse ( temp_tree_ , del_node ) : if isinstance ( temp_tree_ , dict ) : if temp_tree_ [ 'split' ] != - 1 : if temp_tree_ [ 'node' ] == del_node : del temp_tree_ [ 'sr' ] del temp_tree_ [ 'sl' ] del temp_tree_ [ 'node' ] temp_tree_ [ 'split' ] = - 1 else : for k in [ 'sl' , 'sr' ] : recourse ( temp_tree_ [ k ] , del_node ) return None recourse ( temp_tree , node ) return temp_tree
Private function that eliminate node from tree.

        Parameters
        ----------

        tree : object

        node : int
            node to be eliminated from tree

        Returns
        -------

        pruned_tree : object