(self, node=None, level=0)
Return a text-based representation of the tree.

        Parameters
        ----------
        node : LP_SIMPLE_TREE_NODE, optional (default=None)
            Tree node. Used to construct representation of the
            tree under this node.
            If not provided, node is considered root node.

        level : int, optional (defaul=0)
            Level of the node. Used for line indentation.

        Returns
        -------
        tree : str
            Text-based representation of the tree.
Return a text-based representation of the tree.
Return a text - based representation of the tree .
def to_string(self, node=None, level=0):
        """Return a text-based representation of the tree.

        Parameters
        ----------
        node : LP_SIMPLE_TREE_NODE, optional (default=None)
            Tree node. Used to construct representation of the
            tree under this node.
            If not provided, node is considered root node.

        level : int, optional (defaul=0)
            Level of the node. Used for line indentation.

        Returns
        -------
        tree : str
            Text-based representation of the tree.
        """
        if node is None:
            if self.node is None:
                return '(null node)'
            else:
                node = self.node
        n = node.contents
        if self.type == Classification:
            format_str = format_leaf = format_node = None
        else:
            format_str = f"({self.domain.class_var.format_str}: %s)"
            format_leaf = " --> " + format_str
            format_node = "%s " + format_str
        if n.children_size == 0:
            if self.type == Classification:
                node_cont = [round(n.dist[i], 1)
                             for i in range(self.cls_vals)]
                index = node_cont.index(max(node_cont))
                major_class = self.cls_vars[0].values[index]
                return ' --> %s (%s)' % (major_class, node_cont)
            else:
                return format_leaf % (n.sum / n.n, n.n)
        else:
            attr = self.dom_attr[n.split_attr]
            node_desc = attr.name
            indent = '\n' + '   ' * level
            if self.type == Classification:
                node_cont = [round(n.dist[i], 1)
                             for i in range(self.cls_vals)]
                ret_str = indent + '%s (%s)' % (node_desc, node_cont)
            else:
                ret_str = indent + format_node % (node_desc, n.sum / n.n, n.n)
            for i in range(n.children_size):
                if attr.is_continuous:
                    split = '<=' if i % 2 == 0 else '>'
                    split += attr.format_str % n.split
                    ret_str += indent + ': %s' % split
                else:
                    ret_str += indent + ': %s' % attr.values[i]
                ret_str += self.to_string(n.children[i], level + 1)
            return ret_str
def to_string ( self , node = None , level = 0 ) : if node is None : if self . node is None : return '(null node)' else : node = self . node n = node . contents if self . type == Classification : format_str = format_leaf = format_node = None else : format_str = f"({self.domain.class_var.format_str}: %s)" format_leaf = " --> " + format_str format_node = "%s " + format_str if n . children_size == 0 : if self . type == Classification : node_cont = [ round ( n . dist [ i ] , 1 ) for i in range ( self . cls_vals ) ] index = node_cont . index ( max ( node_cont ) ) major_class = self . cls_vars [ 0 ] . values [ index ] return ' --> %s (%s)' % ( major_class , node_cont ) else : return format_leaf % ( n . sum / n . n , n . n ) else : attr = self . dom_attr [ n . split_attr ] node_desc = attr . name indent = '\n' + '   ' * level if self . type == Classification : node_cont = [ round ( n . dist [ i ] , 1 ) for i in range ( self . cls_vals ) ] ret_str = indent + '%s (%s)' % ( node_desc , node_cont ) else : ret_str = indent + format_node % ( node_desc , n . sum / n . n , n . n ) for i in range ( n . children_size ) : if attr . is_continuous : split = '<=' if i % 2 == 0 else '>' split += attr . format_str % n . split ret_str += indent + ': %s' % split else : ret_str += indent + ': %s' % attr . values [ i ] ret_str += self . to_string ( n . children [ i ] , level + 1 ) return ret_str