Changeset 9267:0b956c903961 in orange


Ignore:
Timestamp:
11/24/11 11:13:02 (2 years ago)
Author:
markotoplak
Branch:
default
Convert:
28bbed82310490deb77f3583b57d520e3bd08d19
Message:

Orange.classification.tree. dump -> format.

Location:
orange
Files:
8 edited

Legend:

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

    r9182 r9267  
    233233    >>> learner.stop.min_instances = 5.0 
    234234    >>> tree = learner(data) 
    235     >>> print tree.dump() 
     235    >>> print tree 
    236236    tear_rate=reduced: none (100.00%) 
    237237    tear_rate=normal 
     
    248248    >>> learner.stop.max_majority = 0.5 
    249249    >>> tree = learner(data) 
    250     >>> print tree.dump() 
     250    >>> print tree 
    251251    none (62.50%) 
    252252 
     
    715715certain elements. 
    716716 
    717 The easiest way to print the tree is to call :func:`TreeClassifier.dump` 
    718 without any arguments:: 
    719  
    720     >>> print tree.dump() 
     717The easiest way to print the tree is to print :func:`TreeClassifier`:: 
     718 
     719    >>> print tree 
    721720    petal width<0.800: Iris-setosa (100.00%) 
    722721    petal width>=0.800 
     
    830829the node requires a custom format string:: 
    831830 
    832     >>> print tree.dump(leaf_str="%V (%M out of %N)") 
     831    >>> print tree.format(leaf_str="%V (%M out of %N)") 
    833832    petal width<0.800: Iris-setosa (50.000 out of 50.000) 
    834833    petal width>=0.800 
     
    843842compared to the entire data set and to the parent node:: 
    844843 
    845     >>> print tree.dump(leaf_str="%V (%^MbA%, %^MbP%)") 
     844    >>> print tree.format(leaf_str="%V (%^MbA%, %^MbP%)") 
    846845    petal width<0.800: Iris-setosa (100%, 100%) 
    847846    petal width>=0.800 
     
    908907:: 
    909908 
    910     tree.dump(leaf_str="%V", node_str=".") 
     909    tree.format(leaf_str="%V", node_str=".") 
    911910  
    912911The output:: 
     
    928927of virginicas decreases down the tree try:: 
    929928 
    930     print tree.dump(leaf_str='%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', node_str='.') 
     929    print tree.format(leaf_str='%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', node_str='.') 
    931930 
    932931Interpretation: ``CbA="Iris-virginica"`` is  
     
    950949    |    |    |    petal length>=4.850: 86.0% (95.6%) 
    951950 
    952 If :meth:`~TreeClassifier.dump` cannot compute something, in this case 
     951If :meth:`~TreeClassifier.format` cannot compute something, in this case 
    953952because the root has no parent, it prints out a dot. 
    954953 
     
    957956to the parent and the predicted class in the leaves:: 
    958957 
    959     >>> print tree.dump(leaf_str='"%V   %D %.2DbP %.2dbP"', node_str='"%D %.2DbP %.2dbP"') 
     958    >>> print tree.format(leaf_str='"%V   %D %.2DbP %.2dbP"', node_str='"%D %.2DbP %.2dbP"') 
    960959    root: [50.000, 50.000, 50.000] . . 
    961960    |    petal width<0.800: [50.000, 0.000, 0.000] [1.00, 0.00, 0.00] [3.00, 0.00, 0.00]: 
     
    977976 
    978977The regression trees examples use a tree induced from the housing data 
    979 set. Without other argumets, :meth:`TreeClassifier.dump` prints the 
     978set. Without other argumets, :meth:`TreeClassifier.format` prints the 
    980979following:: 
    981980 
     
    998997the 90% confidence intervals in the leaves, use:: 
    999998 
    1000     >>> print tree.dump(leaf_str="[SE: %E]\t %V %I(90)", node_str="[SE: %E]") 
     999    >>> print tree.format(leaf_str="[SE: %E]\t %V %I(90)", node_str="[SE: %E]") 
    10011000    root: [SE: 0.409] 
    10021001    |    RM<6.941: [SE: 0.306] 
     
    10351034it with values in the parent nodes use:: 
    10361035 
    1037     >>> print tree.dump(leaf_str="%C<22 (%cbP<22)", node_str=".") 
     1036    >>> print tree.format(leaf_str="%C<22 (%cbP<22)", node_str=".") 
    10381037    root: 277.000 (.) 
    10391038    |    RM<6.941: 273.000 (1.160) 
     
    10591058interval [20, 22] and print out the proportions as percents use:: 
    10601059 
    1061     >>> print tree.dump(leaf_str="%C![20,22] (%^cbP![20,22]%)", node_str=".") 
     1060    >>> print tree.format(leaf_str="%C![20,22] (%^cbP![20,22]%)", node_str=".") 
    10621061 
    10631062The format string  ``%c![20, 22]`` denotes the proportion of instances 
     
    10881087------------------------- 
    10891088 
    1090 :meth:`TreeClassifier.dump`'s argument :obj:`user_formats` can be used to 
    1091 print other information.  :obj:`~TreeClassifier.dump.user_formats` should 
     1089:meth:`TreeClassifier.format`'s argument :obj:`user_formats` can be used to 
     1090print other information.  :obj:`~TreeClassifier.format.user_formats` should 
    10921091contain a list of tuples with a regular expression and a function to be 
    10931092called when that expression is found in the format string. Expressions 
     
    15671566        return self.dump() 
    15681567    
     1568 
    15691569    def dump(self):   
    15701570        """ 
     
    15781578            data = Orange.data.Table("voting") 
    15791579            c45 = Orange.classification.tree.C45Learner(data) 
    1580             print c45.dump() 
     1580            print c45 
    15811581 
    15821582        prints 
     
    16131613        """ 
    16141614        return  _c45_printTree0(self.tree, self.class_var, 0) 
     1615 
     1616    format = dump 
    16151617 
    16161618def _c45_showBranch(node, classvar, lev, i): 
     
    25792581     
    25802582    def __str__(self): 
    2581         return self.dump() 
     2583        return self.format() 
    25822584 
    25832585    @Orange.misc.deprecated_keywords({"fileName": "file_name", \ 
     
    25852587        "userFormats": "user_formats", "minExamples": "min_examples", \ 
    25862588        "maxDepth": "max_depth", "simpleFirst": "simple_first"}) 
    2587     def dump(self, leaf_str = "", node_str = "", \ 
     2589    def format(self, leaf_str = "", node_str = "", \ 
    25882590            user_formats=[], min_examples=0, max_depth=1e10, \ 
    25892591            simple_first=True): 
     
    26192621            max_depth, simple_first, self).dumpTree() 
    26202622 
     2623    dump = format 
     2624 
    26212625    @Orange.misc.deprecated_keywords({"fileName": "file_name", \ 
    26222626        "leafStr": "leaf_str", "nodeStr": "node_str", \ 
     
    26302634        """ Print the tree to a file in a format used by `GraphViz 
    26312635        <http://www.research.att.com/sw/tools/graphviz>`_.  Uses the 
    2632         same parameters as :meth:`dump` plus two which define the shape 
     2636        same parameters as :meth:`format` plus two which define the shape 
    26332637        of internal nodes and leaves of the tree: 
    26342638 
  • orange/doc/Orange/rst/code/orngTree1.py

    r8148 r9267  
    1010for format in formats: 
    1111    print '\n\n*** FORMAT: "%s"\n' % format 
    12     print tree.dump(leaf_str=format) 
     12    print tree.format(leaf_str=format) 
    1313 
    1414formats2 = [("%V", "."), ('%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', '.'), ("%V   %D %.2DbP %.2dbP", "%D %.2DbP %.2dbP")] 
    1515for fl, fn in formats2: 
    16     print tree.dump(leaf_str=fl, node_str=fn) 
     16    print tree.format(leaf_str=fl, node_str=fn) 
    1717 
    1818 
     
    2222for format in formats: 
    2323    print '\n\n*** FORMAT: "%s"\n' % format 
    24     print tree.dump(leaf_str=format) 
     24    print tree.format(leaf_str=format) 
    2525 
    2626formats2 = [("[SE: %E]\t %V %I(90)", "[SE: %E]"), ("%C<22 (%cbP<22)", "."), ("%C![20,22] (%^cbP![20,22]%)", ".")] 
    2727for fl, fn in formats2: 
    28     print tree.dump(leaf_str=fl, node_str=fn) 
     28    print tree.format(leaf_str=fl, node_str=fn) 
  • orange/doc/Orange/rst/code/orngTree2.py

    r8986 r9267  
    3131    +"B"+Orange.classification.tree.by), replaceB)] 
    3232             
    33 print tree.dump(leaf_str="%V %^B% (%^3.2BbP%)", user_formats=my_format) 
     33print tree.format(leaf_str="%V %^B% (%^3.2BbP%)", user_formats=my_format) 
  • orange/doc/Orange/rst/code/tree2.py

    r8216 r9267  
    1111print "BIG TREE:" 
    1212tree1 = Orange.classification.tree.TreeLearner(data) 
    13 print tree1.dump(leaf_str="%m", node_str=".") 
     13print tree1.format(leaf_str="%m", node_str=".") 
    1414 
    1515print "\nPRE-PRUNED TREE:" 
    1616tree2 = Orange.classification.tree.TreeLearner(data, max_majority=0.7) 
    17 print tree2.dump(leaf_str="%m", node_str=".") 
     17print tree2.format(leaf_str="%m", node_str=".") 
    1818 
  • orange/doc/Orange/rst/code/tree3.py

    r8148 r9267  
    1616f = lambda examples, weightID, contingency: def_stop(examples, weightID, contingency) or randint(1, 5) == 1 
    1717l = Orange.classification.tree.TreeLearner(data, stop=f) 
    18 print l.dump() 
     18print l 
    1919 
    2020print "\nRANDOM STOPING:" 
    2121f = lambda x,y,z: randint(1, 5)==1 
    2222l = Orange.classification.tree.TreeLearner(data, stop=f) 
    23 print l.dump() 
     23print l 
  • orange/doc/Orange/rst/code/tree_c45.py

    r8999 r9267  
    3333 
    3434tree = Orange.classification.tree.C45Learner(data) 
    35 print tree.dump() 
     35print tree 
    3636print 
    3737 
  • orange/doc/Orange/rst/code/treelearner.py

    r8148 r9267  
    4141learner.stop.min_examples = 5.0 
    4242tree = learner(data) 
    43 print tree.dump() 
     43print tree 
    4444 
    4545print "\n\nTree with maxMajority = 0.5" 
    4646learner.stop.max_majority = 0.5 
    4747tree = learner(data) 
    48 print tree.dump() 
     48print tree 
  • orange/doc/Orange/rst/code/treestructure.py

    r8148 r9267  
    5050 
    5151print "\n\nUnpruned tree" 
    52 print tree_classifier.dump() 
     52print tree_classifier 
    5353 
    5454def cut_tree(node, level): 
     
    6464print "\n\nPruned tree" 
    6565cut_tree(tree_classifier.tree, 2) 
    66 print tree_classifier.dump() 
     66print tree_classifier 
    6767 
Note: See TracChangeset for help on using the changeset viewer.