Changeset 9567:73ff6ea797da in orange


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

Tree: format -> to_string.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/tree2.py

    r9372 r9567  
    1111print "BIG TREE:" 
    1212tree1 = Orange.classification.tree.TreeLearner(data) 
    13 print tree1.format(leaf_str="%m", node_str=".") 
     13print tree1.to_string(leaf_str="%m", node_str=".") 
    1414 
    1515print "\nPRE-PRUNED TREE:" 
    1616tree2 = Orange.classification.tree.TreeLearner(data, max_majority=0.7) 
    17 print tree2.format(leaf_str="%m", node_str=".") 
     17print tree2.to_string(leaf_str="%m", node_str=".") 
    1818 
  • 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 
  • orange/setup.py

    r9068 r9567  
    2424from subprocess import check_call 
    2525 
    26 from types import * 
     26import types 
    2727 
    2828from distutils.dep_util import newer_group 
     
    3232from distutils.sysconfig import get_python_inc, get_config_var 
    3333import numpy 
    34 numpy_include_dir = numpy.get_include(); 
     34numpy_include_dir = numpy.get_include() 
    3535python_include_dir = get_python_inc(plat_specific=1) 
    3636 
     
    9191            self.library_dirs.append(self.build_lib)  
    9292        else: 
    93             self.library_dirs.append("./")  
     93            self.library_dirs.append("./orange") 
    9494         
    9595    def build_extension(self, ext): 
     
    128128        ## mostly copied from build_extension 
    129129        sources = ext.sources 
    130         if sources is None or type(sources) not in (ListType, TupleType): 
     130        if sources is None or type(sources) not in (types.ListType, types.TupleType): 
    131131            raise DistutilsSetupError, \ 
    132132                  ("in 'ext_modules' option (extension '%s'), " + 
     
    219219        ## mostly copied from build_extension, changed 
    220220        sources = ext.sources 
    221         if sources is None or type(sources) not in (ListType, TupleType): 
     221        if sources is None or type(sources) not in (types.ListType, types.TupleType): 
    222222            raise DistutilsSetupError, \ 
    223223                  ("in 'ext_modules' option (extension '%s'), " + 
     
    469469import fnmatch 
    470470matches = [] 
     471os.chdir("orange") 
    471472for root, dirnames, filenames in os.walk('Orange'): #Recursively find '__init__.py's 
    472473  for filename in fnmatch.filter(filenames, '__init__.py'): 
    473474      matches.append(os.path.join(root, filename)) 
    474475packages = [os.path.dirname(pkg).replace(os.path.sep, '.') for pkg in matches] 
     476os.chdir("..") 
    475477 
    476478if have_setuptools: 
     
    493495      download_url = "http://orange.biolab.si/svn/orange/trunk", 
    494496      packages = packages + ["", 
    495                              "OrangeCanvas",  
     497                             "OrangeCanvas", 
    496498                             "OrangeWidgets",  
    497499                             "OrangeWidgets.Associate", 
     
    508510                             "doc", 
    509511                             ], 
    510       package_dir = {"": "."}, 
     512      package_dir = {"": "orange"}, 
    511513      package_data = {"OrangeCanvas": ["icons/*.png", "orngCanvas.pyw", "WidgetTabs.txt"], 
    512514                      "OrangeWidgets": ["icons/*.png", "icons/backgrounds/*.png", "report/index.html"], 
     
    522524                      "OrangeWidgets.plot.primitives": ["*.obj"], 
    523525                      "doc": ["datasets/*.tab", ], 
    524                       "": ["orangerc.cfg"]  
     526                      "": ["orangerc.cfg"] 
    525527                      }, 
    526528      ext_modules = [include_ext, orange_ext, orangeom_ext, orangene_ext, corn_ext, statc_ext], 
    527529      extra_path=("orange", "orange"), 
    528       scripts = ["orange-canvas"], 
     530      scripts = ["orange/orange-canvas"], 
    529531      license = "GNU General Public License (GPL)", 
    530532      keywords = ["data mining", "machine learning", "artificial intelligence"], 
Note: See TracChangeset for help on using the changeset viewer.