Ignore:
Timestamp:
01/25/12 21:00:31 (2 years ago)
Author:
markotoplak
Branch:
default
Message:

Tree: format -> to_string.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/classification/tree.py

    r9538 r9567  
    820820the node requires a custom format string:: 
    821821 
    822     >>> print tree.format(leaf_str="%V (%M out of %N)") 
     822    >>> print tree.to_string(leaf_str="%V (%M out of %N)") 
    823823    petal width<0.800: Iris-setosa (50.000 out of 50.000) 
    824824    petal width>=0.800 
     
    833833compared to the entire data set and to the parent node:: 
    834834 
    835     >>> print tree.format(leaf_str="%V (%^MbA%, %^MbP%)") 
     835    >>> print tree.to_string(leaf_str="%V (%^MbA%, %^MbP%)") 
    836836    petal width<0.800: Iris-setosa (100%, 100%) 
    837837    petal width>=0.800 
     
    898898:: 
    899899 
    900     tree.format(leaf_str="%V", node_str=".") 
     900    tree.to_string(leaf_str="%V", node_str=".") 
    901901  
    902902The output:: 
     
    918918of virginicas decreases down the tree try:: 
    919919 
    920     print tree.format(leaf_str='%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', node_str='.') 
     920    print tree.to_string(leaf_str='%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', node_str='.') 
    921921 
    922922Interpretation: ``CbA="Iris-virginica"`` is  
     
    940940    |    |    |    petal length>=4.850: 86.0% (95.6%) 
    941941 
    942 If :meth:`~TreeClassifier.format` cannot compute something, in this case 
     942If :meth:`~TreeClassifier.to_string` cannot compute something, in this case 
    943943because the root has no parent, it prints out a dot. 
    944944 
     
    947947to the parent and the predicted class in the leaves:: 
    948948 
    949     >>> print tree.format(leaf_str='"%V   %D %.2DbP %.2dbP"', node_str='"%D %.2DbP %.2dbP"') 
     949    >>> print tree.to_string(leaf_str='"%V   %D %.2DbP %.2dbP"', node_str='"%D %.2DbP %.2dbP"') 
    950950    root: [50.000, 50.000, 50.000] . . 
    951951    |    petal width<0.800: [50.000, 0.000, 0.000] [1.00, 0.00, 0.00] [3.00, 0.00, 0.00]: 
     
    967967 
    968968The regression trees examples use a tree induced from the housing data 
    969 set. Without other argumets, :meth:`TreeClassifier.format` prints the 
     969set. Without other argumets, :meth:`TreeClassifier.to_string` prints the 
    970970following:: 
    971971 
     
    988988the 90% confidence intervals in the leaves, use:: 
    989989 
    990     >>> print tree.format(leaf_str="[SE: %E]\t %V %I(90)", node_str="[SE: %E]") 
     990    >>> print tree.to_string(leaf_str="[SE: %E]\t %V %I(90)", node_str="[SE: %E]") 
    991991    root: [SE: 0.409] 
    992992    |    RM<6.941: [SE: 0.306] 
     
    10251025it with values in the parent nodes use:: 
    10261026 
    1027     >>> print tree.format(leaf_str="%C<22 (%cbP<22)", node_str=".") 
     1027    >>> print tree.to_string(leaf_str="%C<22 (%cbP<22)", node_str=".") 
    10281028    root: 277.000 (.) 
    10291029    |    RM<6.941: 273.000 (1.160) 
     
    10491049interval [20, 22] and print out the proportions as percents use:: 
    10501050 
    1051     >>> print tree.format(leaf_str="%C![20,22] (%^cbP![20,22]%)", node_str=".") 
     1051    >>> print tree.to_string(leaf_str="%C![20,22] (%^cbP![20,22]%)", node_str=".") 
    10521052 
    10531053The format string  ``%c![20, 22]`` denotes the proportion of instances 
     
    10781078------------------------- 
    10791079 
    1080 :meth:`TreeClassifier.format`'s argument :obj:`user_formats` can be used to 
     1080:meth:`TreeClassifier.to_string`'s argument :obj:`user_formats` can be used to 
    10811081print other information.  :obj:`~TreeClassifier.format.user_formats` should 
    10821082contain a list of tuples with a regular expression and a function to be 
     
    16001600        return  _c45_printTree0(self.tree, self.class_var, 0) 
    16011601 
    1602     format = dump 
     1602    to_string = dump 
    16031603 
    16041604def _c45_showBranch(node, classvar, lev, i): 
     
    25672567     
    25682568    def __str__(self): 
    2569         return self.format() 
     2569        return self.to_string() 
    25702570 
    25712571    @Orange.misc.deprecated_keywords({"fileName": "file_name", \ 
     
    25732573        "userFormats": "user_formats", "minExamples": "min_examples", \ 
    25742574        "maxDepth": "max_depth", "simpleFirst": "simple_first"}) 
    2575     def format(self, leaf_str = "", node_str = "", \ 
     2575    def to_string(self, leaf_str = "", node_str = "", \ 
    25762576            user_formats=[], min_examples=0, max_depth=1e10, \ 
    25772577            simple_first=True): 
     
    26072607            max_depth, simple_first, self).dumpTree() 
    26082608 
    2609     dump = format 
     2609    dump = to_string 
    26102610 
    26112611    @Orange.misc.deprecated_keywords({"fileName": "file_name", \ 
     
    26202620        """ Print the tree to a file in a format used by `GraphViz 
    26212621        <http://www.research.att.com/sw/tools/graphviz>`_.  Uses the 
    2622         same parameters as :meth:`format` plus two which define the shape 
     2622        same parameters as :meth:`to_string` plus two which define the shape 
    26232623        of internal nodes and leaves of the tree: 
    26242624 
Note: See TracChangeset for help on using the changeset viewer.