Changeset 7485:e60fe4191982 in orange


Ignore:
Timestamp:
02/04/11 17:27:05 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
4bb0779f3316e5761f32fbe363a0d1aaae008c7a
Message:

Removed "Tree" prefix where it was not needed.

File:
1 edited

Legend:

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

    r7474 r7485  
    1414 
    1515Classification trees are represented as a tree-like hierarchy of 
    16 :obj:`TreeNode` classes. 
    17  
    18 .. class:: TreeNode 
    19  
    20     TreeNode stores information about the learning examples belonging  
     16:obj:`Node` classes. 
     17 
     18.. class:: Node 
     19 
     20    Node stores information about the learning examples belonging  
    2121    to the node, a branch selector, a list of branches (if the node is  
    2222    not a leaf) with their descriptions and strengths, and a classifier. 
     
    3535        flag to true. Note that even when the flag is not  
    3636        set, the contingencies get computed and stored to  
    37         :obj:`TreeNode`, but are removed shortly afterwards.  
     37        :obj:`Node`, but are removed shortly afterwards.  
    3838        The details are given in the  
    3939        description of the :obj:`TreeLearnerBase` object. 
     
    4444        corresponding ID of /weight meta attribute. The root of the 
    4545        tree stores a "master table" of examples, while other nodes' 
    46         :obj:`orange.ExampleTable` contain reference to examples in 
    47         the root's :obj:`orange.ExampleTable`. Examples are only stored 
     46        :obj:`Orange.data.Table` contain reference to examples in 
     47        the root's :obj:`Orange.data.Table`. Examples are only stored 
    4848        if a corresponding flag (:obj:`storeExamples`) has been 
    4949        set while building the tree; to conserve the space, storing 
     
    5757        used to decide the final class (or class distribution) of an 
    5858        example. If it's an internal node, it is stored if 
    59         :obj:`TreeNode`'s flag :obj:`storeNodeClassifier` 
     59        :obj:`Node`'s flag :obj:`storeNodeClassifier` 
    6060        is set. Since the :obj:`nodeClassifier` is needed by 
    61         :obj:`TreeDescender` and for pruning (see far below), 
     61        :obj:`Descender` and for pruning (see far below), 
    6262        this is the default behaviour; space consumption of the default 
    6363        :obj:`DefaultClassifier` is rather small. You should 
    6464        never disable this if you intend to prune the tree later. 
    6565 
    66     If the node is a leaf, the remaining fields are <code>None</code>.  
     66    If the node is a leaf, the remaining fields are None.  
    6767    If it's an internal node, there are several additional fields. 
    6868 
    6969    .. attribute:: branches 
    7070 
    71         Stores a list of subtrees, given as :obj:`TreeNode`. 
    72         An element can be <code>None</code>; in this case the node is empty. 
     71        Stores a list of subtrees, given as :obj:`Node`. 
     72        An element can be None; in this case the node is empty. 
    7373 
    7474    .. attribute:: branchDescriptions 
    7575 
    7676        A list with string descriptions for branches, constructed by 
    77         :obj:`TreeSplitConstructor`. It can contain different kinds 
     77        :obj:`SplitConstructor`. It can contain different kinds 
    7878        of descriptions, but basically, expect things like 'red' or '>12.3'. 
    7979 
     
    9191        type :obj:`orange.Classifier`, since its job is similar to that 
    9292        of a classifier: it gets an example and returns discrete 
    93         :obj:`orange.Value` in range [0, <CODE>len(branches)-1</CODE>]. 
     93        :obj:`orange.Value` in range :samp:`[0, len(branches)-1]`. 
    9494        When an example cannot be classified to any branch, the selector 
    9595        can return a :obj:`orange.Value` containing a special value 
     
    9898        :obj:`branchSelector`'s opinion of how to divide the 
    9999        example between the branches. Whether the proposition will be 
    100         used or not depends upon the chosen :obj:`TreeExampleSplitter` 
    101         (when learning) or :obj:`TreeDescender` (when classifying). 
     100        used or not depends upon the chosen :obj:`ExampleSplitter` 
     101        (when learning) or :obj:`Descender` (when classifying). 
    102102 
    103103    The lists :obj:`branches`, :obj:`branchDescriptions` and 
     
    123123    component :obj:`descender`. 
    124124 
    125     :obj:`TreeDescender` is an abstract object which is given an example 
     125    :obj:`Descender` is an abstract object which is given an example 
    126126    and whose basic job is to descend as far down the tree as possible, 
    127127    according to the values of example's attributes. The 
    128     :obj:`TreeDescender`: calls the node's :obj:`branchSelector` to get  
     128    :obj:`Descender`: calls the node's :obj:`branchSelector` to get  
    129129    the branch index. If it's a simple index, the corresponding branch  
    130130    is followed. If not, it's up to descender to decide what to do, and 
     
    139139       when things went wrong, but the descender smoothed them by  
    140140       selecting a single branch and continued the descend. In this 
    141        case, the descender returns the reached :obj:`TreeNode`. 
     141       case, the descender returns the reached :obj:`Node`. 
    142142    #. :obj:`branchSelector` returned a distribution and the  
    143        :obj:`TreeDescender` decided to stop the descend at this  
     143       :obj:`Descender` decided to stop the descend at this  
    144144       (internal) node.  Again, descender returns the current  
    145        :obj:`TreeNode` and nothing else. 
     145       :obj:`Node` and nothing else. 
    146146    #. :obj:`branchSelector` returned a distribution and the  
    147        :obj:`TreeNode` wants to split the example (i.e., to decide the  
     147       :obj:`Node` wants to split the example (i.e., to decide the  
    148148       class by voting).  
    149149 
    150     It returns a :obj:`TreeNode` and the vote-weights for the branches.  
     150    It returns a :obj:`Node` and the vote-weights for the branches.  
    151151    The weights can correspond to the distribution returned by 
    152152    :obj:`branchSelector`, to the number of learning examples that 
     
    154154 
    155155    :obj:`TreeClassifier` uses the descender to descend from the root.  
    156     If it returns only a :obj:`TreeNode` and no distribution, the  
     156    If it returns only a :obj:`Node` and no distribution, the  
    157157    descend should stop; it does not matter whether it's a leaf (the 
    158158    first case above) or an internal node (the second case). The node's 
    159159    :obj:`nodeClassifier` is used to decide the class. If the descender 
    160     returns a :obj:`TreeNode` and a distribution, the :obj:`TreeClassifier` 
     160    returns a :obj:`Node` and a distribution, the :obj:`TreeClassifier` 
    161161    recursively calls itself for each of the subtrees and the  
    162162    predictions are weighted as requested by the descender. 
     
    173173If you'd like to understand how the classification works in C++,  
    174174start reading at :obj:`TTreeClassifier::vote`. It gets a  
    175 :obj:`TreeNode`, an :obj:`orange.Example`> and a distribution of  
     175:obj:`Node`, an :obj:`orange.Example`> and a distribution of  
    176176vote weights. For each node, it calls the  
    177177:obj:`TTreeClassifier::classDistribution` and then multiplies  
     
    180180 
    181181A new overload of :obj:`TTreeClassifier::classDistribution` gets 
    182 an additional parameter, a :obj:`TreeNode`. This is done  
     182an additional parameter, a :obj:`Node`. This is done  
    183183for the sake of recursion. The normal version of  
    184184:obj:`classDistribution` simply calls the overloaded with a  
     
    197197leaf's :obj:`nodeClassifier`. Otherwise, it calls  
    198198:obj:`vote`>. From now on, :obj:`vote` and  
    199 <code>classDistribution</code> interweave down the tree and return  
     199:obj:`classDistribution` interweave down the tree and return  
    200200a distribution of predictions. :obj:`operator()` then simply  
    201201chooses the most probable class. 
     
    210210 
    211211Components that govern the structure of the tree are :obj:`split` 
    212 (of type :obj:`TreeSplitConstructor`), :obj:`stop` (of  
    213 type :obj:`TreeStopCriteria` and :obj:`exampleSplitter` 
    214 (of type :obj:`TreeExampleSplitter`). 
    215  
    216 .. class:: TreeSplitConstructor 
     212(of type :obj:`SplitConstructor`), :obj:`stop` (of  
     213type :obj:`StopCriteria` and :obj:`exampleSplitter` 
     214(of type :obj:`ExampleSplitter`). 
     215 
     216.. class:: SplitConstructor 
    217217 
    218218    Finds a suitable criteria for dividing the learning (and later testing) 
     
    224224    :obj:`storeNodeClassifier` is left true). 
    225225 
    226     The :obj:`TreeSplitConstructor` should use the domain contingency 
     226    The :obj:`SplitConstructor` should use the domain contingency 
    227227    when possible. The reasons are two-fold; one is that it's faster 
    228228    and the other is that the contingency matrices are not necessarily 
     
    237237    attribute). 
    238238 
    239     :obj:`TreeSplitConstructor` returns most of the data we talked 
    240     about when describing the :obj:`TreeNode`. It returns a classifier 
    241     to be used as :obj:`TreeNode`'s :obj:`branchSelector`, a list of 
     239    :obj:`SplitConstructor` returns most of the data we talked 
     240    about when describing the :obj:`Node`. It returns a classifier 
     241    to be used as :obj:`Node`'s :obj:`branchSelector`, a list of 
    242242    branch descriptions and a list with the number of examples that 
    243     go into each branch. Just what we need for the :obj:`TreeNode`. 
     243    go into each branch. Just what we need for the :obj:`Node`. 
    244244    It can return an empty list for the number of examples in branches; 
    245245    in this case, the :obj:`TreeLearnerBase` will find the number itself 
     
    260260    negative index. 
    261261 
    262     A :obj:`TreeSplitConstructor` can veto the further tree induction 
     262    A :obj:`SplitConstructor` can veto the further tree induction 
    263263    by returning no classifier. This can happen for many reasons. 
    264264    A general one is related to number of examples in the branches. 
    265     :obj:`TreeSplitConstructor` has a field :obj:`minSubset`, 
     265    :obj:`SplitConstructor` has a field :obj:`minSubset`, 
    266266    which sets the minimal number of examples in a branch; null nodes, 
    267267    however, are allowed. If there is no split where this condition 
    268     is met, :obj:`TreeSplitConstructor` stops the induction. 
     268    is met, :obj:`SplitConstructor` stops the induction. 
    269269 
    270270    .. attribute:: minSubset 
     
    294294 
    295295 
    296 .. class:: TreeStopCriteria 
     296.. class:: StopCriteria 
    297297 
    298298    Given a set of examples, weight ID and contingency matrices, decide 
     
    303303    majority classes. 
    304304 
    305     As opposed to :obj:`TreeSplitConstructor` and similar basic classes, 
    306     :obj:`TreeStopCriteria` is not an abstract but a fully functional 
     305    As opposed to :obj:`SplitConstructor` and similar basic classes, 
     306    :obj:`StopCriteria` is not an abstract but a fully functional 
    307307    class that provides the basic stopping criteria. That is, the tree 
    308308    induction stops when there is at most one example left; in this case, 
     
    318318        the examples are in the same class (but not for counting the 
    319319        examples). Derived classes should use the contingencies whenever 
    320         possible. If contingencies are not given, :obj:`TreeStopCriteria` 
     320        possible. If contingencies are not given, :obj:`StopCriteria` 
    321321        will work without them. Derived classes should also use them if 
    322322        they are available, but otherwise compute them only when they 
     
    324324 
    325325 
    326 .. class:: TreeExampleSplitter 
    327  
    328     Just like the :obj:`TreeDescender` decides the branch for an 
    329     example during classification, the :obj:`TreeExampleSplitter` 
     326.. class:: ExampleSplitter 
     327 
     328    Just like the :obj:`Descender` decides the branch for an 
     329    example during classification, the :obj:`ExampleSplitter` 
    330330    sorts the learning examples into branches. 
    331331 
    332     :obj:`TreeExampleSplitter` is given a :obj:`TreeNode` (from which  
     332    :obj:`ExampleSplitter` is given a :obj:`Node` (from which  
    333333    it can use different stuff, but most of splitters only use the  
    334334    :obj:`branchSelector`), a set of examples to be divided, and  
     
    337337 
    338338    Subsets are usually stored as :obj:`ExamplePointerTable`'s. Most  
    339     of :obj:`TreeExampleSplitters` simply call the node's  
     339    of :obj:`ExampleSplitters` simply call the node's  
    340340    :obj:`branchSelector` and assign examples to corresponding  
    341341    branches. When the value is unknown they choose a particular  
     
    352352    say, three subsets, has three new meta attributes, one for each 
    353353    subset. ID's of weight meta attributes are returned by the 
    354     :obj:`TreeExampleSplitter` to be used at induction of the 
     354    :obj:`ExampleSplitter` to be used at induction of the 
    355355    corresponding subtrees. 
    356356 
     
    379379    .. attribute:: split 
    380380 
    381         Object of type :obj:`TreeSplitConstructor`. Default value,  
     381        Object of type :obj:`SplitConstructor`. Default value,  
    382382        provided by :obj:`TreeLearnerBase`, is :obj:`SplitConstructor_Combined` 
    383383        with separate constructors for discrete and continuous attributes.  
     
    389389    .. attribute:: stop 
    390390 
    391         Object of type :obj:`TreeStopCriteria`. The default stopping 
     391        Object of type :obj:`StopCriteria`. The default stopping 
    392392        criterion stops induction when all examples in a node belong  
    393393        to the same class. 
     
    395395    .. attribute:: splitter 
    396396 
    397         Object of type :obj:`TreeExampleSplitter`. The default splitter 
    398         is :obj:`TreeExampleSplitter_UnknownsAsSelector` that splits 
     397        Object of type :obj:`ExampleSplitter`. The default splitter 
     398        is :obj:`ExampleSplitter_UnknownsAsSelector` that splits 
    399399        the learning examples according to distributions given by the 
    400400        selector. 
     
    421421        Descending component that the induces :obj:`TreeClassifier` 
    422422        will use. Default descender is  
    423         :obj:`TreeDescender_UnknownMergeAsSelector` which votes using  
     423        :obj:`Descender_UnknownMergeAsSelector` which votes using  
    424424        the :obj:`branchSelector`'s distribution for vote weights. 
    425425 
     
    435435 
    436436        Decides whether to store class distributions, contingencies  
    437         and examples in :obj:`TreeNode`, and whether the  
     437        and examples in :obj:`Node`, and whether the  
    438438        :obj:`nodeClassifier` should be build for internal nodes.  
    439439        By default, distributions and node classifiers are stored,  
     
    441441        memory by not storing distributions but storing contingencies, 
    442442        since distributions actually points to the same distribution 
    443         that is stored in <code>contingency.classes</code>. 
     443        that is stored in :obj:`contingency.classes`. 
    444444 
    445445    The :obj:`TreeLearnerBase` first sets the defaults for missing 
     
    472472    The contingency matrix is computed next. This happens 
    473473    even if the flag :obj:`storeContingencies` is false. 
    474     If the <code>contingencyComputer</code> is given we use it, 
     474    If the :obj:`contingencyComputer` is given we use it, 
    475475    otherwise we construct just an ordinary contingency matrix. 
    476476 
    477477    A :obj:`stop` is called to see whether it's worth to continue. If  
    478     not, a :obj:`nodeClassifier` is built and the :obj:`TreeNode` is  
     478    not, a :obj:`nodeClassifier` is built and the :obj:`Node` is  
    479479    returned. Otherwise, a :obj:`nodeClassifier` is only built if  
    480480    :obj:`forceNodeClassifier` flag is set. 
    481481 
    482     To get a :obj:`TreeNode`'s :obj:`nodeClassifier`, the  
     482    To get a :obj:`Node`'s :obj:`nodeClassifier`, the  
    483483    :obj:`nodeLearner`'s :obj:`smartLearn` function is called with  
    484484    the given examples, weight ID and the just computed matrix. If  
     
    494494    If the induction is to continue, a :obj:`split` component is called.  
    495495    If it fails to return a branch selector, induction stops and the  
    496     :obj:`TreeNode` is returned. 
     496    :obj:`Node` is returned. 
    497497 
    498498    :obj:`TreeLearnerBase` than uses :obj:`ExampleSplitter` to divide  
     
    516516======= 
    517517 
    518 Tree pruners derived from :obj:`TreePruner` can be given either a 
    519 :obj:`TreeNode` (presumably, but not necessarily a root) or a 
    520 :obj:`TreeClassifier`. The result is a new, pruned :obj:`TreeNode` 
     518Tree pruners derived from :obj:`Pruner` can be given either a 
     519:obj:`Node` (presumably, but not necessarily a root) or a 
     520:obj:`TreeClassifier`. The result is a new, pruned :obj:`Node` 
    521521or a new :obj:`TreeClassifier` with a pruned tree. The original 
    522522tree remains intact. 
    523523 
    524524Note however that pruners construct only a shallow copy of a tree. 
    525 The pruned tree's :obj:`TreeNode` contain references to the same 
     525The pruned tree's :obj:`Node` contain references to the same 
    526526contingency matrices, node classifiers, branch selectors, ... 
    527527as the original tree. Thus, you may modify a pruned tree structure 
     
    545545 
    546546Several classes described above are already functional and can 
    547 (and mostly will) be used as they are. Those classes are :obj:`TreeNode`, 
     547(and mostly will) be used as they are. Those classes are :obj:`Node`, 
    548548:obj:`TreeLearnerBase` and :obj:`TreeClassifier`. This section describe  
    549549the other classes. 
    550550 
    551 Classes :obj:`TreeSplitConstructor`, :obj:`TreeStopCriteria`,  
    552 :obj:`TreeExampleSplitter`, :obj:`TreeDescender`, :obj:`orange.Learner` 
     551Classes :obj:`SplitConstructor`, :obj:`StopCriteria`,  
     552:obj:`ExampleSplitter`, :obj:`Descender`, :obj:`orange.Learner` 
    553553and :obj:`Classifier` are among the Orange classes that can be subtyped  
    554554in Python and have the call operator overloadedd in such a way that it 
     
    558558separate page, dedicated to callbacks to Python XXXXXXXXXX. 
    559559 
    560 TreeSplitConstructors 
     560SplitConstructors 
    561561===================== 
    562562 
     
    566566and continuous classes... Most split constructors work either for 
    567567discrete or for continuous attributes. The suggested practice is 
    568 to use a :obj:`TreeSplitConstructor_Combined` that can handle 
     568to use a :obj:`SplitConstructor_Combined` that can handle 
    569569both by simply delegating attributes to specialized split constructors. 
    570570 
     
    573573simply skip the attribute. It is your responsibility to use a correct 
    574574split constructor for your dataset. (May we again suggest 
    575 using :obj:`TreeSplitConstructor_Combined`?) 
     575using :obj:`SplitConstructor_Combined`?) 
    576576 
    577577The same components can be used either for inducing classification and 
    578578regression trees. The only component that needs to be chosen accordingly 
    579 is the 'measure' attribute for the :obj:`TreeSplitConstructor_Measure` 
     579is the 'measure' attribute for the :obj:`SplitConstructor_Measure` 
    580580class (and derived classes). 
    581581 
    582 .. class:: TreeSplitConstructor_Measure 
    583  
    584     Bases: :class:`TreeSplitConstructor` 
     582.. class:: SplitConstructor_Measure 
     583 
     584    Bases: :class:`SplitConstructor` 
    585585 
    586586    An abstract base class for split constructors that employ  
    587587    a :obj:`orange.MeasureAttribute` to assess a quality of a split. At present, 
    588     all split constructors except for :obj:`TreeSplitConstructor_Combined` 
     588    all split constructors except for :obj:`SplitConstructor_Combined` 
    589589    are derived from this class. 
    590590 
     
    604604        :obj:`measure` component. Default is 0.0. 
    605605 
    606 .. class:: TreeSplitConstructor_Attribute 
    607  
    608     Bases: :class:`TreeSplitConstructor_Measure` 
     606.. class:: SplitConstructor_Attribute 
     607 
     608    Bases: :class:`SplitConstructor_Measure` 
    609609 
    610610    Attempts to use a discrete attribute as a split; each value of the  
     
    621621    node's subtrees. 
    622622 
    623 .. class:: TreeSplitConstructor_ExhaustiveBinary 
    624  
    625     Bases: :class:`TreeSplitConstructor_Measure` 
     623.. class:: SplitConstructor_ExhaustiveBinary 
     624 
     625    Bases: :class:`SplitConstructor_Measure` 
    626626 
    627627    Works on discrete attributes. For each attribute, it determines 
     
    644644 
    645645 
    646 .. class:: TreeSplitConstructor_Threshold 
    647  
    648     Bases: :class:`TreeSplitConstructor_Measure` 
     646.. class:: SplitConstructor_Threshold 
     647 
     648    Bases: :class:`SplitConstructor_Measure` 
    649649 
    650650    This is currently the only constructor for splits with continuous  
     
    660660    "<threshold" and ">=threshold". The attribute is not spent. 
    661661 
    662 .. class:: TreeSplitConstructor_OneAgainstOthers 
     662.. class:: SplitConstructor_OneAgainstOthers 
    663663     
    664     Bases: :class:`TreeSplitConstructor_Measure` 
     664    Bases: :class:`SplitConstructor_Measure` 
    665665 
    666666    Undocumented. 
    667667 
    668 .. class:: TreeSplitConstructor_Combined 
    669  
    670     Bases: :class:`TreeSplitConstructor` 
     668.. class:: SplitConstructor_Combined 
     669 
     670    Bases: :class:`SplitConstructor` 
    671671 
    672672    This constructor delegates the task of finding the optimal split  
     
    680680    score; the split constructor for discrete attributes will select 
    681681    one of them. Now, let us suppose that there is a single continuous 
    682     attribute with the same score. :obj:`TreeSplitConstructor_Combined` 
     682    attribute with the same score. :obj:`SplitConstructor_Combined` 
    683683    would randomly select between the proposed discrete attribute and  
    684684    the continuous attribute, not aware of the fact that the discrete 
     
    696696 
    697697        Split constructor for discrete attributes; can be, for instance, 
    698         :obj:`TreeSplitConstructor_Attribute` or  
    699         :obj:`TreeSplitConstructor_ExhaustiveBinary`. 
     698        :obj:`SplitConstructor_Attribute` or  
     699        :obj:`SplitConstructor_ExhaustiveBinary`. 
    700700 
    701701    .. attribute: continuousSplitConstructor 
    702702 
    703703        Split constructor for continuous attributes; at the moment, it  
    704         can be either :obj:`TreeSplitConstructor_Threshold` or a  
     704        can be either :obj:`SplitConstructor_Threshold` or a  
    705705        split constructor you programmed in Python. 
    706706 
     
    708708     
    709709        Split constructor for continuous attributes; at the moment, it  
    710         can be either :obj:`TreeSplitConstructor_Threshold` or a split 
     710        can be either :obj:`SplitConstructor_Threshold` or a split 
    711711        constructor you programmed in Python. 
    712712 
    713713 
    714 TreeStopCriteria and TreeStopCriteria_common 
     714StopCriteria and StopCriteria_common 
    715715============================================ 
    716716 
    717 obj:`TreeStopCriteria` determines when to stop the induction of subtrees, as  
     717obj:`StopCriteria` determines when to stop the induction of subtrees, as  
    718718described in detail in description of the learning process. XXXXXXXXXX 
    719719 
    720 .. class:: TreeStopCriteria_common 
    721  
    722     :obj:`TreeStopCriteria` contains additional criteria for pre-pruning: 
     720.. class:: StopCriteria_common 
     721 
     722    :obj:`StopCriteria` contains additional criteria for pre-pruning: 
    723723    it checks the proportion of majority class and the number of weighted 
    724724    examples. 
     
    735735        Example count is weighed. 
    736736 
    737 .. class:: TreeStopCriteria_Python 
     737.. class:: StopCriteria_Python 
    738738 
    739739    Undocumented. 
    740740 
    741 Classes derived from TreeExampleSplitter 
     741Classes derived from ExampleSplitter 
    742742======================================== 
    743743 
    744 :obj:`TreeExampleSplitter` is the third crucial component of 
     744:obj:`ExampleSplitter` is the third crucial component of 
    745745:obj:`TreeLearnerBase`. Its function is described in  
    746746description of the learning process. XXXXXXXXXX 
    747747 
    748 .. class:: TreeExampleSplitter_IgnoreUnknowns 
    749  
    750     Bases: :class:`TreeExampleSplitter` 
     748.. class:: ExampleSplitter_IgnoreUnknowns 
     749 
     750    Bases: :class:`ExampleSplitter` 
    751751 
    752752    Simply ignores the examples for which no single branch can be determined. 
    753753 
    754 .. class:: TreeExampleSplitter_UnknownsToCommon 
    755  
    756     Bases: :class:`TreeExampleSplitter` 
     754.. class:: ExampleSplitter_UnknownsToCommon 
     755 
     756    Bases: :class:`ExampleSplitter` 
    757757 
    758758    Places all such examples to a branch with the highest number of 
     
    760760    random and then used for all examples. 
    761761 
    762 .. class:: TreeExampleSplitter_UnknownsToAll 
    763  
    764     Bases: :class:`TreeExampleSplitter` 
     762.. class:: ExampleSplitter_UnknownsToAll 
     763 
     764    Bases: :class:`ExampleSplitter` 
    765765 
    766766    Places examples with unknown value of the attribute into all branches. 
    767767 
    768 .. class:: TreeExampleSplitter_UnknownsToRandom 
    769  
    770     Bases: :class:`TreeExampleSplitter` 
     768.. class:: ExampleSplitter_UnknownsToRandom 
     769 
     770    Bases: :class:`ExampleSplitter` 
    771771 
    772772    Selects a random branch for such examples. 
    773773 
    774 .. class:: TreeExampleSplitter_UnknownsToBranch 
    775  
    776     Bases: :class:`TreeExampleSplitter` 
     774.. class:: ExampleSplitter_UnknownsToBranch 
     775 
     776    Bases: :class:`ExampleSplitter` 
    777777 
    778778    Constructs an additional branch to contain all such examples.  
    779779    The branch's description is "unknown". 
    780780 
    781 .. class:: TreeExampleSplitter_UnknownsAsBranchSizes 
    782  
    783     Bases: :class:`TreeExampleSplitter` 
     781.. class:: ExampleSplitter_UnknownsAsBranchSizes 
     782 
     783    Bases: :class:`ExampleSplitter` 
    784784 
    785785    Splits examples with unknown value of the attribute according to  
    786786    proportions of examples in each branch. 
    787787 
    788 .. class:: TreeExampleSplitter_UnknownsAsSelector 
    789  
    790     Bases: :class:`TreeExampleSplitter` 
     788.. class:: ExampleSplitter_UnknownsAsSelector 
     789 
     790    Bases: :class:`ExampleSplitter` 
    791791 
    792792    Splits examples with unknown value of the attribute according to  
     
    794794    as proportions of examples in branches). 
    795795 
    796 TreeDescender and derived classes 
     796Descender and derived classes 
    797797================================= 
    798798 
    799 This is a classifier's counterpart for :obj:`TreeExampleSplitter`. It  
     799This is a classifier's counterpart for :obj:`ExampleSplitter`. It  
    800800decides the destiny of examples that need to be classified and cannot 
    801801be unambiguously put in a branch. The detailed function of this class 
    802802is given in description of classification with trees. XXXXXX 
    803803 
    804 .. class:: TreeDescender 
     804.. class:: Descender 
    805805 
    806806    An abstract base object for tree descenders. 
     
    814814        contains a node and weights of votes for subtrees (a list of floats). 
    815815 
    816         :obj:`TreeDescender`'s that never split examples always descend 
     816        :obj:`Descender`'s that never split examples always descend 
    817817        to a leaf, but they differ in the treatment of examples with 
    818818        unknown values (or, in general, examples for which a branch 
    819819        cannot be determined at some node(s) the tree). 
    820         :obj:`TreeDescender`'s that do split examples differ in returned 
     820        :obj:`Descender`'s that do split examples differ in returned 
    821821        vote weights. 
    822822 
    823 .. class:: TreeDescender_UnknownsToNode 
    824  
    825     Bases: :obj:`TreeDescender` 
     823.. class:: Descender_UnknownsToNode 
     824 
     825    Bases: :obj:`Descender` 
    826826 
    827827    When example cannot be classified into a single branch, the 
     
    832832    them after the induction, that's all) 
    833833 
    834 .. class:: TreeDescender_UnknownsToBranch 
    835  
    836     Bases: :obj:`TreeDescender` 
     834.. class:: Descender_UnknownsToBranch 
     835 
     836    Bases: :obj:`Descender` 
    837837 
    838838    Classifies examples with unknown value to a special branch. This 
    839839    makes sense only if the tree itself was constructed with 
    840     :obj:`TreeExampleSplitter_UnknownsToBranch`. 
    841  
    842 .. class:: TreeDescender_UnknownsToCommonBranch 
    843  
    844     Bases: :obj:`TreeDescender` 
     840    :obj:`ExampleSplitter_UnknownsToBranch`. 
     841 
     842.. class:: Descender_UnknownsToCommonBranch 
     843 
     844    Bases: :obj:`Descender` 
    845845 
    846846    Classifies examples with unknown values to the branch with the 
     
    848848    random branch is chosen for each example that is to be classified. 
    849849 
    850 .. class:: TreeDescender_UnknownsToCommonSelector 
    851  
    852     Bases: :obj:`TreeDescender` 
     850.. class:: Descender_UnknownsToCommonSelector 
     851 
     852    Bases: :obj:`Descender` 
    853853 
    854854    Classifies examples with unknown values to the branch which received  
    855855    the highest recommendation by the selector. 
    856856 
    857 .. class:: TreeDescender_MergeAsBranchSizes 
    858  
    859     Bases: :obj:`TreeDescender` 
     857.. class:: Descender_MergeAsBranchSizes 
     858 
     859    Bases: :obj:`Descender` 
    860860 
    861861    Makes the subtrees vote for the example's class; the vote is 
    862862    weighted according to the sizes of the branches. 
    863863 
    864 .. class:: TreeDescender_MergeAsSelector 
    865  
    866     Bases: :obj:`TreeDescender` 
     864.. class:: Descender_MergeAsSelector 
     865 
     866    Bases: :obj:`Descender` 
    867867 
    868868    Makes the subtrees vote for the example's class; the vote is  
    869869    weighted according to the selectors proposal. 
    870870 
    871 TreePruner and derived classes 
     871Pruner and derived classes 
    872872============================== 
    873873 
     
    875875    pair: classification trees; pruning 
    876876 
    877 Classes derived from :obj:`TreePruner` prune the trees as a 
     877Classes derived from :obj:`Pruner` prune the trees as a 
    878878described in the section pruning XXXXXXXX - make sure you read it  
    879879to understand what the pruners will do to your trees. 
    880880 
    881 .. class:: TreePruner 
     881.. class:: Pruner 
    882882 
    883883    This is an abstract base class which defines nothing useful, only  
     
    889889        a tree node; the result is of the same type as the argument. 
    890890 
    891 .. class:: TreePruner_SameMajority 
    892  
    893     Bases: :class:`TreePruner` 
     891.. class:: Pruner_SameMajority 
     892 
     893    Bases: :class:`Pruner` 
    894894 
    895895    In Orange, a tree can have a non-trivial subtrees (i.e. subtrees  
     
    899899    However, this can be undesired when we're only interested in the  
    900900    class prediction or a simple tree interpretation. The  
    901     :obj:`TreePruner_SameMajority` prunes the tree so that there is no 
     901    :obj:`Pruner_SameMajority` prunes the tree so that there is no 
    902902    subtree in which all the nodes would have the same majority class. 
    903903 
     
    910910    have (at least one) common majority class. If so, they can be pruned. 
    911911 
    912 .. class:: TreePruner_m 
    913  
    914     Bases: :class:`TreePruner` 
     912.. class:: Pruner_m 
     913 
     914    Bases: :class:`Pruner` 
    915915 
    916916    Prunes a tree by comparing m-estimates of static and dynamic  
     
    926926 
    927927This page does not provide examples for programming your own components,  
    928 such as, for instance, a :obj:`TreeSplitConstructor`. Those examples 
     928such as, for instance, a :obj:`SplitConstructor`. Those examples 
    929929can be found on a page dedicated to callbacks to Python XXXXXXXX. 
    930930 
     
    956956    10 
    957957 
    958 Don't forget that this was only an excercise - :obj:`TreeNode` has a  
    959 built-in method :obj:`TreeNode.treeSize` that does exactly the same. 
     958Don't forget that this was only an excercise - :obj:`Node` has a  
     959built-in method :obj:`Node.treeSize` that does exactly the same. 
    960960 
    961961Let us now write a simple script that prints out a tree. The recursive 
     
    973973After handling null nodes, remaining nodes are internal nodes and leaves. 
    974974For internal nodes, we print a node description consisting of the 
    975 attribute's name and distribution of classes. :obj:`TreeNode`'s branch 
     975attribute's name and distribution of classes. :obj:`Node`'s branch 
    976976description is, for all currently defined splits, an instance of a 
    977977class derived from :obj:`orange.Classifier` (in fact, it is a 
     
    10021002... but we won't. Let us learn how to handle arguments of different 
    10031003types. Let's write a function that will accept either a :obj:`TreeClassifier` 
    1004 or a :obj:`TreeNode`; just like TreePruners XXXXXX, remember? Part of `treestructure.py`_, uses `lenses.tab`_. 
     1004or a :obj:`Node`; just like Pruners XXXXXX, remember? Part of `treestructure.py`_, uses `lenses.tab`_. 
    10051005 
    10061006.. literalinclude:: code/treestructure.py 
     
    10091009It's fairly straightforward: if :obj:`x` is of type derived from  
    10101010:obj:`orange.TreeClassifier`, we print :obj:`x.tree`; if it's  
    1011 :obj:`TreeNode` we just call :obj:`printTree0` with :obj:`x`. If it's  
     1011:obj:`Node` we just call :obj:`printTree0` with :obj:`x`. If it's  
    10121012of some other type, we don't know how to handle it and thus raise  
    10131013an exception. (Note that we could also use  
     
    10371037 
    10381038For a final exercise, let us write a simple pruning procedure. It will  
    1039 be written entirely in Python, unrelated to any :obj:`TreePruner`. Our 
     1039be written entirely in Python, unrelated to any :obj:`Pruner`. Our 
    10401040procedure will limit the tree depth - the maximal depth (here defined 
    10411041as the number of internal nodes on any path down the tree) shall be 
     
    11501150============ 
    11511151 
    1152 .. class:: TreeNodeList 
     1152.. class:: NodeList 
    11531153 
    11541154    Undocumented. 
    11551155 
    1156 .. class:: C45TreeNodeList 
     1156.. class:: C45NodeList 
    11571157 
    11581158    Undocumented. 
     
    11711171components that contain exactly the same information plus what is needed 
    11721172to make them visible from Python. To be sure that the algorithm behaves 
    1173 just as the original, we use a dedicated class :class:`C45TreeNode` 
     1173just as the original, we use a dedicated class :class:`C45Node` 
    11741174instead of reusing the components used by Orange's tree inducer 
    1175 (ie, :class:`TreeNode`). This, however, could be done and probably 
    1176 will be done in the future; we shall still retain :class:`C45TreeNode`  
    1177 but offer transformation to :class:`TreeNode` so that routines 
     1175(ie, :class:`Node`). This, however, could be done and probably 
     1176will be done in the future; we shall still retain :class:`C45Node`  
     1177but offer transformation to :class:`Node` so that routines 
    11781178that work on Orange trees will also be usable for C45 trees. 
    11791179 
     
    12911291    A faithful reimplementation of Quinlan's function from C4.5. The only 
    12921292    difference (and the only reason it's been rewritten) is that it uses 
    1293     a tree composed of :class:`C45TreeNode` instead of C4.5's 
     1293    a tree composed of :class:`C45Node` instead of C4.5's 
    12941294    original tree structure. 
    12951295 
    12961296    .. attribute:: tree 
    12971297 
    1298         C4.5 tree stored as a tree of :obj:`C45TreeNode`. 
    1299  
    1300  
    1301 .. class:: C45TreeNode 
     1298        C4.5 tree stored as a tree of :obj:`C45Node`. 
     1299 
     1300 
     1301.. class:: C45Node 
    13021302 
    13031303    This class is a reimplementation of the corresponding *struct* from 
     
    13061306    .. attribute:: nodeType 
    13071307 
    1308         Type of the node:  :obj:`C45TreeNode.Leaf` (0),  
    1309         :obj:`C45TreeNode.Branch` (1), :obj:`C45TreeNode.Cut` (2), 
    1310         :obj:`C45TreeNode.Subset` (3). "Leaves" are leaves, "branches" 
     1308        Type of the node:  :obj:`C45Node.Leaf` (0),  
     1309        :obj:`C45Node.Branch` (1), :obj:`C45Node.Cut` (2), 
     1310        :obj:`C45Node.Subset` (3). "Leaves" are leaves, "branches" 
    13111311        split examples based on values of a discrete attribute, 
    13121312        "cuts" cut them according to a threshold value of a continuous 
     
    13831383There's nothing special about using :obj:`C45Classifier` - it's  
    13841384just like any other. To demonstrate what the structure of  
    1385 :class:`C45TreeNode`'s looks like, will show a script that prints  
     1385:class:`C45Node`'s looks like, will show a script that prints  
    13861386it out in the same format as C4.5 does. 
    13871387 
     
    13901390Leaves are the simplest. We just print out the value contained 
    13911391in :samp:`node.leaf`. Since this is not a qualified value (ie.,  
    1392 :obj:`C45TreeNode` does not know to which attribute it belongs), we need to 
     1392:obj:`C45Node` does not know to which attribute it belongs), we need to 
    13931393convert it to a string through :obj:`classVar`, which is passed as an 
    13941394extra argument to the recursive part of printTree. 
     
    14171417For a bit more complex example, here's how to write your own stop 
    14181418function. The example itself is more funny than useful. It constructs 
    1419 and prints two trees. For the first one we define the <code>defStop</code> 
     1419and prints two trees. For the first one we define the *defStop* 
    14201420function, which is used by default, and combine it with a random function 
    14211421so that the stop criteria will also be met in additional 20% of the cases 
    1422 when <code>defStop</code> is false. The second tree is build such that it 
     1422when *defStop* is false. The second tree is build such that it 
    14231423considers only the random function as the stopping criteria. Note that in 
    14241424the second case lambda function still has three parameters, since this is 
     
    15621562<p class="header">part of <a href="orngTree1.py">orngTree1.py</a></p> 
    15631563<xmp class="code">import orange, orngTree 
    1564 data = orange.ExampleTable("iris") 
     1564data = Orange.data.Table("iris") 
    15651565tree = orngTree.TreeLearner(data, maxDepth=3) 
    15661566</xmp> 
     
    19231923It therefore takes the value predicted at the node  
    19241924(:samp:`node.nodeClassifier.defaultValue` ), converts it to a string 
    1925 and passes it to <code>insertStr</code> to do the replacement. 
     1925and passes it to *insertStr* to do the replacement. 
    19261926 
    19271927A more complex regular expression is the one for the proportion of 
     
    20762076    :: 
    20772077 
    2078         import orange 
    2079         import Orange.classification.tree as tree 
    2080  
    2081         data = orange.ExampleTable("voting") 
    2082         c45 = tree.C45Learner(data) 
    2083         tree.printTreeC45(c45) 
     2078        import Orange 
     2079 
     2080        data = Orange.data.Table("voting") 
     2081        c45 = Orange.classification.tree.C45Learner(data) 
     2082        Orange.classification.tree.printTreeC45(c45) 
    20842083 
    20852084    will print out 
     
    21482147         
    21492148        Defines a function that will be used in place of 
    2150         :obj:`TreeSplitConstructor`.  
     2149        :obj:`SplitConstructor`.  
    21512150        Useful when prototyping new tree induction 
    21522151        algorithms. When this parameter is defined, other parameters that 
     
    21542153        include :obj:`binarization`, :obj:`measure`, 
    21552154        :obj:`worstAcceptable` and :obj:`minSubset` (Default: 
    2156         :class:TreeSplitConstructor_Combined  
     2155        :class:SplitConstructor_Combined  
    21572156        with separate constructors for discrete and continuous attributes. 
    21582157        Discrete attributes are used as they are, while  
     
    21642163    .. attribute:: binarization 
    21652164 
    2166         If 1, :class:`TreeSplitConstructor_ExhaustiveBinary` is used. 
    2167         If 2, use class:`TreeSplitConstructor_OneAgainstOthers`. If 
    2168         0, do not use binarization (use class:`TreeSplitConstructor_Attribute`). 
     2165        If 1, :class:`SplitConstructor_ExhaustiveBinary` is used. 
     2166        If 2, use class:`SplitConstructor_OneAgainstOthers`. If 
     2167        0, do not use binarization (use class:`SplitConstructor_Attribute`). 
    21692168        Default: 0. 
    21702169 
     
    22362235 
    22372236        Used for passing a function which is used in place of 
    2238         :class:`TreeStopCriteria`. Useful when prototyping new 
     2237        :class:`StopCriteria`. Useful when prototyping new 
    22392238        tree induction algorithms. See a documentation on  
    2240         :class:`TreeStopCriteria` for more info on this function.  
     2239        :class:`StopCriteria` for more info on this function.  
    22412240        When used, parameters  :obj:`maxMajority` and :obj:`minExamples`  
    22422241        will not be  considered (default: None). XXXXX To je pisalo spodaj. 
     
    22602259 
    22612260        Determines whether to store class distributions, contingencies and 
    2262         examples in :class:`TreeNode`, and whether the :obj:`nodeClassifier` 
     2261        examples in :class:`Node`, and whether the :obj:`nodeClassifier` 
    22632262        should be build for internal nodes. By default everything except  
    22642263        :obj:`storeExamples` is enabled. You won't save any memory by not storing  
     
    23982397    :type tree: :class:`TreeClassifier` 
    23992398    """ 
    2400     return __countNodes(type(tree) == orange.TreeClassifier and tree.tree or tree) 
     2399    return __countNodes(isinstance(tree == Orange.classification.tree.TreeClassifier) and tree.tree or tree) 
    24012400 
    24022401 
     
    24182417    :type tree: :class:`TreeClassifier` 
    24192418    """ 
    2420     return __countLeaves(type(tree) == orange.TreeClassifier and tree.tree or tree) 
     2419    return __countLeaves(isinstance(tree == Orange.classification.tree.TreeClassifier) and tree.tree or tree) 
    24212420 
    24222421 
Note: See TracChangeset for help on using the changeset viewer.