stackboost/core.py
def __prune(self, tree: DecisionNode = None) -> DecisionNode:
        """
        Method used to prune the decision tree in order to avoid overfitting

        :param tree: Sub tree of the decision tree (node)
        :return: DecisionNode
        """
        if tree is None:
            tree = self.root

        if not tree.is_leaf() and not tree.true_branch.is_leaf() and not tree.false_branch.is_leaf():
            tree.true_branch = self.__prune(tree.true_branch)
            tree.false_branch = self.__prune(tree.false_branch)

        if not tree.is_leaf() and tree.true_branch.is_leaf() and tree.false_branch.is_leaf():
            if self._impurity_calculation(tree.target, tree.true_branch.target,
                                          tree.false_branch.target) - self.average_gain * self.gamma_percentage < 0:
                return DecisionNode(value=self._leaf_value_calculation(tree.target), target=tree.target)

        return tree

        Method used to prune the decision tree in order to avoid overfitting

        :param tree: Sub tree of the decision tree (node)
        :return: DecisionNode
        
Method used to prune the decision tree in order to avoid overfitting
Method used to prune the decision tree in order to avoid overfitting
def __prune(self, tree: DecisionNode = None) -> DecisionNode:
        if tree is None:
            tree = self.root
        if not tree.is_leaf() and not tree.true_branch.is_leaf() and not tree.false_branch.is_leaf():
            tree.true_branch = self.__prune(tree.true_branch)
            tree.false_branch = self.__prune(tree.false_branch)
        if not tree.is_leaf() and tree.true_branch.is_leaf() and tree.false_branch.is_leaf():
            if self._impurity_calculation(tree.target, tree.true_branch.target,
                                          tree.false_branch.target) - self.average_gain * self.gamma_percentage < 0:
                return DecisionNode(value=self._leaf_value_calculation(tree.target), target=tree.target)
        return tree
def __prune ( self , tree : DecisionNode = None ) -> DecisionNode : if tree is None : tree = self . root if not tree . is_leaf ( ) and not tree . true_branch . is_leaf ( ) and not tree . false_branch . is_leaf ( ) : tree . true_branch = self . __prune ( tree . true_branch ) tree . false_branch = self . __prune ( tree . false_branch ) if not tree . is_leaf ( ) and tree . true_branch . is_leaf ( ) and tree . false_branch . is_leaf ( ) : if self . _impurity_calculation ( tree . target , tree . true_branch . target , tree . false_branch . target ) - self . average_gain * self . gamma_percentage < 0 : return DecisionNode ( value = self . _leaf_value_calculation ( tree . target ) , target = tree . target ) return tree
Method used to prune the decision tree in order to avoid overfitting
Method used to prune the decision tree in order to avoid overfitting
"""
        Method used to prune the decision tree in order to avoid overfitting

        :param tree: Sub tree of the decision tree (node)
        :return: DecisionNode
        """
None
self
tree
DecisionNode
Sub tree of the decision tree (node)
Sub tree of the decision tree ( node )