Changeset 10015:80f04d2d6ce7 in orange


Ignore:
Timestamp:
02/07/12 23:37:35 (2 years ago)
Author:
Jure Zbontar <jure.zbontar@…>
Branch:
default
Message:

Fixed doctests in tree.py

Location:
Orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/classification/tree.py

    r9923 r10015  
    1717The following code builds a :obj:`TreeClassifier` on the Iris data set 
    1818(with the depth limited to three levels): 
     19 
     20>>> 1 + 1 
     212 
    1922 
    2023.. literalinclude:: code/orngTree1.py 
     
    108111This example works with the lenses data set: 
    109112 
    110 .. literalinclude:: code/treestructure.py 
    111    :lines: 7-10 
     113.. 
     114    .. literalinclude:: code/treestructure.py 
     115       :lines: 7-10 
     116 
     117>>> import Orange 
     118>>> lenses = Orange.data.Table("lenses") 
     119>>> tree_classifier = Orange.classification.tree.TreeLearner(lenses) 
    112120 
    113121The following function counts the number of nodes in a tree: 
    114122 
    115 .. literalinclude:: code/treestructure.py 
    116    :lines: 12-21 
     123.. 
     124    .. literalinclude:: code/treestructure.py 
     125       :lines: 12-21 
     126 
     127>>> def tree_size(node): 
     128...    if not node: 
     129...        return 0 
     130... 
     131...    size = 1 
     132...    if node.branch_selector: 
     133...        for branch in node.branches: 
     134...            size += tree_size(branch) 
     135... 
     136...    return size 
    117137 
    118138If node is None, the function above return 0. Otherwise, the size is 1 
     
    122142 
    123143    >>> tree_size(tree_classifier.tree) 
    124     10 
     144    15 
    125145 
    126146Note that a :obj:`Node` already has a built-in method 
     
    154174:obj:`TreeClassifier` or a :obj:`Node` can be written as follows: 
    155175 
    156 .. literalinclude:: code/treestructure.py 
    157    :lines: 43-49 
     176    .. literalinclude:: code/treestructure.py 
     177       :lines: 43-49 
    158178 
    159179It's straightforward: if ``x`` is a 
  • Orange/testing/doctest/dtest.py

    r9938 r10015  
    5656 
    5757if __name__ == '__main__': 
    58     base_dirs = [os.path.abspath('../../misc')] 
     58    base_dirs = [os.path.abspath('../../classification')] 
    5959    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.