Changeset 8148:3ae2568c4cf9 in orange


Ignore:
Timestamp:
08/04/11 15:11:31 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
a32182e6c13024952dac66ae536936c54ae1eddf
Message:

Orange.classification.tree - renameing to underscore_separated. References #825.

Location:
orange
Files:
7 edited

Legend:

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

    r8042 r8148  
    7171If node is None, we have a null-node; null nodes don't count, so we 
    7272return 0. Otherwise, the size is 1 (this node) plus the sizes of all 
    73 subtrees. The node is an internal node if it has a :obj:`branchSelector`; 
     73subtrees. The node is an internal node if it has a :obj:`branch_selector`; 
    7474it there's no selector, it's a leaf. Don't attempt to skip the if 
    7575statement: leaves don't have an empty list of branches, they don't have 
     
    9999of the attribute's name and distribution of classes. :obj:`Node`'s 
    100100branch description is, for all currently defined splits, an instance 
    101 of a class derived from :obj:`orange.Classifier` (in fact, it is 
    102 a :obj:`orange.ClassifierFromVarFD`, but a :obj:`orange.Classifier` 
    103 would suffice), and its :obj:`classVar` points to the attribute we seek. 
     101of a class derived from :obj:`Orange.classification.Classifier`  
     102(in fact, it is 
     103a :obj:`orange.ClassifierFromVarFD`, but a :obj:`Orange.classification.Classifier` 
     104would suffice), and its :obj:`class_var` points to the attribute we seek. 
    104105So we print its name. We will also assume that storing class distributions 
    105106has not been disabled and print them as well.  Then we iterate through 
     
    109110Finally, if the node is a leaf, we print out the distribution of learning 
    110111examples in the node and the class to which the examples in the node 
    111 would be classified. We again assume that the :obj:`nodeClassifier` is 
     112would be classified. We again assume that the :obj:`node_classifier` is 
    112113the default one - a :obj:`DefaultClassifier`. A better print function 
    113114should be aware of possible alternatives. 
     
    162163 
    163164There's nothing to prune at null-nodes or leaves, so we act only when 
    164 :obj:`node` and :obj:`node.branchSelector` are defined. If level is 
     165:obj:`node` and :obj:`node.branch_selector` are defined. If level is 
    165166not zero, we call the function for each branch. Otherwise, we clear the 
    166167selector, branches and branch descriptions. 
     
    217218We can now examine the default stopping parameters. 
    218219 
    219     >>> print learner.stop.maxMajority, learner.stop.minExamples 
     220    >>> print learner.stop.max_majority, learner.stop.min_examples 
    220221    1.0 0.0 
    221222 
     
    225226see what comes out. 
    226227 
    227     >>> learner.stop.minExamples = 5.0 
     228    >>> learner.stop.min_examples = 5.0 
    228229    >>> tree = learner(data) 
    229230    >>> print tree.dump() 
     
    241242the maximal proportion of majority class. 
    242243 
    243     >>> learner.stop.maxMajority = 0.5 
     244    >>> learner.stop.max_majority = 0.5 
    244245    >>> tree = learner(data) 
    245246    >>> print tree.dump() 
     
    271272        Stores a distribution for learning examples belonging to the 
    272273        node.  Storing distributions can be disabled by setting the 
    273         :obj:`_TreeLearner`'s storeDistributions flag to false. 
     274        :obj:`_TreeLearner`'s store_distributions flag to false. 
    274275 
    275276    .. attribute:: contingency 
     
    277278        Stores complete contingency matrices for the learning examples 
    278279        belonging to the node. Storing contingencies can be enabled by 
    279         setting :obj:`_TreeLearner`'s :obj:`storeContingencies` flag to 
     280        setting :obj:`_TreeLearner`'s :obj:`store_contingencies` flag to 
    280281        true. Note that even when the flag is not set, the contingencies 
    281282        get computed and stored to :obj:`Node`, but are removed shortly 
     
    290291        :obj:`Orange.data.Table` contain reference to examples in the 
    291292        root's :obj:`Orange.data.Table`. Examples are only stored if 
    292         a corresponding flag (:obj:`storeExamples`) has been set while 
     293        a corresponding flag (:obj:`store_examples`) has been set while 
    293294        building the tree; to conserve the space, storing is disabled 
    294295        by default. 
    295296 
    296     .. attribute:: nodeClassifier 
     297    .. attribute:: node_classifier 
    297298 
    298299        A classifier (usually, but not necessarily, a 
     
    301302        decide the final class (or class distribution) of an example. If 
    302303        it's an internal node, it is stored if :obj:`Node`'s flag 
    303         :obj:`storeNodeClassifier` is set. Since the :obj:`nodeClassifier` 
     304        :obj:`store_node_classifier` is set. Since the :obj:`node_classifier` 
    304305        is needed by :obj:`Descender` and for pruning (see far below), 
    305306        this is the default behaviour; space consumption of the default 
     
    315316        can be None; in this case the node is empty. 
    316317 
    317     .. attribute:: branchDescriptions 
     318    .. attribute:: branch_descriptions 
    318319 
    319320        A list with string descriptions for branches, constructed by 
     
    321322        descriptions, but basically, expect things like 'red' or '>12.3'. 
    322323 
    323     .. attribute:: branchSizes 
     324    .. attribute:: branch_sizes 
    324325 
    325326        Gives a (weighted) number of training examples that went into 
     
    327328        probabilities when classifying examples with unknown values. 
    328329 
    329     .. attribute:: branchSelector 
     330    .. attribute:: branch_selector 
    330331 
    331332        Gives a branch for each example. The same object is used 
    332         during learning and classifying. The :obj:`branchSelector` 
    333         is of type :obj:`orange.Classifier`, since its job is 
     333        during learning and classifying. The :obj:`branch_selector` 
     334        is of type :obj:`Orange.classification.Classifier`, since its job is 
    334335        similar to that of a classifier: it gets an example and 
    335336        returns discrete :obj:`Orange.data.Value` in range :samp:`[0, 
     
    338339        containing a special value (sVal) which should be a discrete 
    339340        distribution (DiscDistribution). This should represent a 
    340         :obj:`branchSelector`'s opinion of how to divide the example 
     341        :obj:`branch_selector`'s opinion of how to divide the example 
    341342        between the branches. Whether the proposition will be used or not 
    342343        depends upon the chosen :obj:`ExampleSplitter` (when learning) 
    343344        or :obj:`Descender` (when classifying). 
    344345 
    345     The lists :obj:`branches`, :obj:`branchDescriptions` and 
    346     :obj:`branchSizes` are of the same length; all of them are 
     346    The lists :obj:`branches`, :obj:`branch_descriptions` and 
     347    :obj:`branch_sizes` are of the same length; all of them are 
    347348    defined if the node is internal and none if it is a leaf. 
    348349 
    349     .. method:: treeSize() 
     350    .. method:: tree_size() 
    350351         
    351352        Return the number of nodes in the subtrees (including the node, 
     
    371372    and whose basic job is to descend as far down the tree as possible, 
    372373    according to the values of example's attributes. The :obj:`Descender`: 
    373     calls the node's :obj:`branchSelector` to get the branch index. If 
     374    calls the node's :obj:`branch_selector` to get the branch index. If 
    374375    it's a simple index, the corresponding branch is followed. If not, 
    375376    it's up to descender to decide what to do, and that's where descenders 
    376377    differ. A :obj:`descender` can choose a single branch (for instance, 
    377     the one that is the most recommended by the :obj:`branchSelector`) 
     378    the one that is the most recommended by the :obj:`branch_selector`) 
    378379    or it can let the branches vote. 
    379380 
     
    385386       selecting a single branch and continued the descend. In this case, 
    386387       the descender returns the reached :obj:`Node`. 
    387     #. :obj:`branchSelector` returned a distribution and the 
     388    #. :obj:`branch_selector` returned a distribution and the 
    388389       :obj:`Descender` decided to stop the descend at this (internal) 
    389390       node.  Again, descender returns the current :obj:`Node` and 
    390391       nothing else. 
    391     #. :obj:`branchSelector` returned a distribution and the 
     392    #. :obj:`branch_selector` returned a distribution and the 
    392393       :obj:`Node` wants to split the example (i.e., to decide the class 
    393394       by voting). 
     
    395396    It returns a :obj:`Node` and the vote-weights for the branches. 
    396397    The weights can correspond to the distribution returned by 
    397     :obj:`branchSelector`, to the number of learning examples that were 
     398    :obj:`branch_selector`, to the number of learning examples that were 
    398399    assigned to each branch, or to something else. 
    399400 
     
    402403    should stop; it does not matter whether it's a leaf (the first 
    403404    case above) or an internal node (the second case). The node's 
    404     :obj:`nodeClassifier` is used to decide the class. If the descender 
     405    :obj:`node_classifier` is used to decide the class. If the descender 
    405406    returns a :obj:`Node` and a distribution, the :obj:`TreeClassifier` 
    406407    recursively calls itself for each of the subtrees and the predictions 
     
    415416        It gets a :obj:`Node`, an :obj:`Orange.data.Instance` and a 
    416417        distribution of vote weights. For each node, it calls the 
    417         :obj:`classDistribution` and then multiplies and sums the 
     418        :obj:`class_distribution` and then multiplies and sums the 
    418419        distribution. :obj:`vote` returns a normalized distribution 
    419420        of predictions. 
    420421 
    421     .. method:: classDistribution() 
     422    .. method:: class_distribution() 
    422423 
    423424        Gets an additional parameter, a :obj:`Node` (default tree root). 
    424         :obj:`classDistribution` uses :obj:`descender`. If descender 
    425         reaches a leaf, it calls :obj:`nodeClassifier`, otherwise it 
     425        :obj:`class_distribution` uses :obj:`descender`. If descender 
     426        reaches a leaf, it calls :obj:`node_classifier`, otherwise it 
    426427        calls :obj:`vote`. 
    427428 
    428         Thus, the :obj:`vote` and :obj:`classDistribution` are written 
     429        Thus, the :obj:`vote` and :obj:`class_distribution` are written 
    429430        in a form of double recursion. The recursive calls do not happen 
    430431        at each node of the tree but only at nodes where a vote is needed 
     
    434435 
    435436        Calls the descender. If it reaches a leaf, the class is 
    436         predicted by the leaf's :obj:`nodeClassifier`. Otherwise, it calls 
    437         :obj:`vote`. From now on, :obj:`vote` and :obj:`classDistribution` 
     437        predicted by the leaf's :obj:`node_classifier`. Otherwise, it calls 
     438        :obj:`vote`. From now on, :obj:`vote` and :obj:`class_distribution` 
    438439        interweave down the tree and return a distribution of 
    439440        predictions. This method simply chooses the most probable class. 
     
    448449    Components that govern the structure of the tree are 
    449450    :obj:`split` (of type :obj:`SplitConstructor`), :obj:`stop` 
    450     (of type :obj:`StopCriteria` and :obj:`exampleSplitter` (of type 
     451    (of type :obj:`StopCriteria` and :obj:`example_splitter` (of type 
    451452    :obj:`ExampleSplitter`). 
    452453 
     
    459460        are binarized. Gain ratio is used to select attributes.  A minimum 
    460461        of two examples in a leaf is required for discreter and five 
    461         examples in a leaf for continuous attributes.</DD> 
     462        examples in a leaf for continuous attributes. 
    462463 
    463464    .. attribute:: stop 
     
    467468        the same class. 
    468469 
    469     .. attribute:: splitter 
     470    .. attribute:: example_splitter 
    470471 
    471472        Object of type :obj:`ExampleSplitter`. The default splitter is 
     
    473474        examples according to distributions given by the selector. 
    474475 
    475     .. attribute:: contingencyComputer 
     476    .. attribute:: contingency_computer 
    476477     
    477478        By default, this slot is left empty and ordinary contingency 
     
    484485        ignored by some splitting constructors. 
    485486 
    486     .. attribute:: nodeLearner 
     487    .. attribute:: node_learner 
    487488 
    488489        Induces a classifier from examples belonging to a 
    489490        node. The same learner is used for internal nodes 
    490         and for leaves. The default :obj:`nodeLearner` is 
     491        and for leaves. The default :obj:`node_learner` is 
    491492        :obj:`Orange.classification.majority.MajorityLearner`. 
    492493 
     
    495496        Descending component that the induces :obj:`TreeClassifier` will 
    496497        use. Default descender is :obj:`Descender_UnknownMergeAsSelector` 
    497         which votes using the :obj:`branchSelector`'s distribution for 
     498        which votes using the :obj:`branch_selector`'s distribution for 
    498499        vote weights. 
    499500 
    500     .. attribute:: maxDepth 
     501    .. attribute:: max_depth 
    501502 
    502503        Gives maximal tree depth; 0 means that only root is generated. 
     
    506507        this hard limit, you can do so as well. 
    507508 
    508     .. attribute:: storeDistributions, storeContingencies, storeExamples, storeNodeClassifier 
     509    .. attribute:: store_distributions, store_contingencies, store_examples, store_node_classifier 
    509510 
    510511        Decides whether to store class distributions, contingencies and 
    511         examples in :obj:`Node`, and whether the :obj:`nodeClassifier` 
     512        examples in :obj:`Node`, and whether the :obj:`node_classifier` 
    512513        should be build for internal nodes.  By default, distributions and 
    513514        node classifiers are stored, while contingencies and examples are 
     
    524525    examples are in a file or are fed through a filter, they are copied 
    525526    to a table. Even if they are already in a table, they are copied if 
    526     :obj:`storeExamples` is set. This is to assure that pointers remain 
     527    :obj:`store_examples` is set. This is to assure that pointers remain 
    527528    pointing to examples even if the user later changes the example 
    528     table. If they are in the table and the :obj:`storeExamples` flag 
     529    table. If they are in the table and the :obj:`store_examples` flag 
    529530    is clear, we just use them as they are. This will obviously crash 
    530531    in a multi-threaded system if one changes the table during the tree 
     
    543544 
    544545    The contingency matrix is computed next. This happens even if the flag 
    545     :obj:`storeContingencies` is false.  If the :obj:`contingencyComputer` 
     546    :obj:`store_contingencies` is false.  If the :obj:`contingency_computer` 
    546547    is given we use it, otherwise we construct just an ordinary 
    547548    contingency matrix. 
    548549 
    549550    A :obj:`stop` is called to see whether it's worth to continue. If 
    550     not, a :obj:`nodeClassifier` is built and the :obj:`Node` is 
    551     returned. Otherwise, a :obj:`nodeClassifier` is only built if 
     551    not, a :obj:`node_classifier` is built and the :obj:`Node` is 
     552    returned. Otherwise, a :obj:`node_classifier` is only built if 
    552553    :obj:`forceNodeClassifier` flag is set. 
    553554 
    554     To get a :obj:`Node`'s :obj:`nodeClassifier`, the 
    555     :obj:`nodeLearner`'s :obj:`smartLearn` function is called 
     555    To get a :obj:`Node`'s :obj:`node_classifier`, the 
     556    :obj:`node_learner`'s :obj:`smart_learn` function is called 
    556557    with the given examples, weight ID and the just computed 
    557558    matrix. If the learner can use the matrix (and the default, 
    558559    :obj:`Orange.classification.majority.MajorityLearner`, can), it won't 
    559     touch the examples. Thus, a choice of :obj:`contingencyComputer` 
    560     will, in many cases, affect the :obj:`nodeClassifier`. The 
    561     :obj:`nodeLearner` can return no classifier; if so and 
     560    touch the examples. Thus, a choice of :obj:`contingency_computer` 
     561    will, in many cases, affect the :obj:`node_classifier`. The 
     562    :obj:`node_learner` can return no classifier; if so and 
    562563    if the classifier would be needed for classification, 
    563564    the :obj:`TreeClassifier`'s function returns DK or an empty 
     
    573574 
    574575    The contingency gets removed at this point if it is not to be 
    575     stored. Thus, the :obj:`split`, :obj:`stop` and :obj:`exampleSplitter` 
     576    stored. Thus, the :obj:`split`, :obj:`stop` and :obj:`example_splitter` 
    576577    can use the contingency matrices if they will. 
    577578 
     
    615616    contingency computed from examples, apriori class probabilities, a 
    616617    list of candidate attributes it should consider and a node classifier 
    617     (if it was constructed, that is, if :obj:`storeNodeClassifier` 
     618    (if it was constructed, that is, if :obj:`store_node_classifier` 
    618619    is left true). 
    619620 
     
    629630    :obj:`SplitConstructor` returns most of the data we talked 
    630631    about when describing the :obj:`Node`. It returns a classifier 
    631     to be used as :obj:`Node`'s :obj:`branchSelector`, a list of branch 
     632    to be used as :obj:`Node`'s :obj:`branch_selector`, a list of branch 
    632633    descriptions and a list with the number of examples that go into 
    633634    each branch. Just what we need for the :obj:`Node`.  It can return 
     
    651652    by returning no classifier. This can happen for many reasons. 
    652653    A general one is related to number of examples in the branches. 
    653     :obj:`SplitConstructor` has a field :obj:`minSubset`, which sets 
     654    :obj:`SplitConstructor` has a field :obj:`min_subset`, which sets 
    654655    the minimal number of examples in a branch; null nodes, however, 
    655656    are allowed. If there is no split where this condition is met, 
    656657    :obj:`SplitConstructor` stops the induction. 
    657658 
    658     .. attribute:: minSubset 
     659    .. attribute:: min_subset 
    659660 
    660661        Sets the minimal number of examples in non-null leaves. As 
     
    664665    .. method:: __call__(examples, [weightID=0, apriori_distribution, candidates])  
    665666 
    666         Construct a split. Returns a tuple (:obj:`branchSelector`, 
    667         :obj:`branchDescriptions`, :obj:`subsetSizes`, :obj:`quality`, 
     667        Construct a split. Returns a tuple (:obj:`branch_selector`, 
     668        :obj:`branch_descriptions`, :obj:`subsetSizes`, :obj:`quality`, 
    668669        :obj:`spentAttribute`). :obj:`spentAttribute` is -1 if no 
    669670        attribute is completely spent by the split criterion. If no 
    670         split is constructed, the :obj:`selector`, :obj:`branchDescriptions` 
     671        split is constructed, the :obj:`selector`, :obj:`branch_descriptions` 
    671672        and :obj:`subsetSizes` are None, while :obj:`quality` is 0.0 and 
    672673        :obj:`spentAttribute` is -1. 
     
    678679            examples have a weight of 1.0.  
    679680        :param apriori-distribution: Should be of type  
    680             :obj:`orange.Distribution` and candidates should be a Python  
     681            :obj:`Orange.statistics.distribution.Distribution` and candidates should be a Python  
    681682            list of objects which are interpreted as booleans. 
    682683        :param candidates: The split constructor should consider only  
     
    704705        trees. 
    705706 
    706     .. attribute:: worstAcceptable 
     707    .. attribute:: worst_acceptable 
    707708 
    708709        The lowest required split quality for a split to be acceptable. 
     
    720721    highest score, one of them is selected by random. 
    721722 
    722     The constructed :obj:`branchSelector` is an instance of 
     723    The constructed :obj:`branch_selector` is an instance of 
    723724    :obj:`orange.ClassifierFromVarFD` that returns a value of the selected 
    724725    attribute. If the attribute is :obj:`Orange.data.variable.Discrete`, 
    725     :obj:`branchDescription`'s are the attribute's values. The attribute 
     726    :obj:`branch_description`'s are the attribute's values. The attribute 
    726727    is marked as spent, so that it cannot reappear in the node's subtrees. 
    727728 
     
    736737    it returns one of those with the highest score. 
    737738 
    738     The constructed :obj:`branchSelector` is again an instance 
     739    The constructed :obj:`branch_selector` is again an instance 
    739740    :obj:`orange.ClassifierFromVarFD` that returns a value of the 
    740741    selected attribute. This time, however, its :obj:`transformer` 
     
    758759    The attribute that yields the highest binary split is returned. 
    759760 
    760     The constructed :obj:`branchSelector` is again an instance 
     761    The constructed :obj:`branch_selector` is again an instance 
    761762    of :obj:`orange.ClassifierFromVarFD` with an attached 
    762763    :obj:`transformer`. This time, :obj:`transformer` is of type 
    763     :obj:`orange.ThresholdDiscretizer`. The branch descriptions are 
    764     "<threshold" and ">=threshold". The attribute is not spent. 
     764    :obj:`Orange.feature.discretization.ThresholdDiscretizer`. The branch 
     765    descriptions are "<threshold" and ">=threshold". The attribute is 
     766    not spent. 
    765767 
    766768.. class:: SplitConstructor_OneAgainstOthers 
     
    793795    simply choose the first attribute with the highest score anyway.) 
    794796 
    795     The :obj:`branchSelector`, :obj:`branchDescriptions` and whether 
     797    The :obj:`branch_selector`, :obj:`branch_descriptions` and whether 
    796798    the attribute is spent is decided by the winning split constructor. 
    797799 
    798     .. attribute: discreteSplitConstructor 
     800    .. attribute: discrete_split_constructor 
    799801 
    800802        Split constructor for discrete attributes; can be, 
     
    802804        :obj:`SplitConstructor_ExhaustiveBinary`. 
    803805 
    804     .. attribute: continuousSplitConstructor 
     806    .. attribute: continuous_split_constructor 
    805807 
    806808        Split constructor for continuous attributes; at the moment, it  
     
    808810        split constructor you programmed in Python. 
    809811 
    810     .. attribute: continuousSplitConstructor 
     812    .. attribute: continuous_split_constructor 
    811813     
    812814        Split constructor for continuous attributes; at the moment, 
     
    857859    examples. 
    858860 
    859     .. attribute:: maxMajor 
     861    .. attribute:: max_majority 
    860862 
    861863        Maximal proportion of majority class. When this is exceeded, 
    862864        induction stops. 
    863865 
    864     .. attribute:: minExamples 
     866    .. attribute:: min_examples 
    865867 
    866868        Minimal number of examples in internal leaves. Subsets with 
    867         less than :obj:`minExamples` examples are not split any further. 
     869        less than :obj:`min_examples` examples are not split any further. 
    868870        Example count is weighed. 
    869871 
     
    881883:obj:`ExampleSplitter` is given a :obj:`Node` (from which  
    882884it can use different stuff, but most of splitters only use the  
    883 :obj:`branchSelector`), a set of examples to be divided, and  
     885:obj:`branch_selector`), a set of examples to be divided, and  
    884886the weight ID. The result is a list of subsets of examples 
    885887and, optionally, a list of new weight ID's. 
    886888 
    887889Most :obj:`ExampleSplitter` classes simply call the node's 
    888 :obj:`branchSelector` and assign examples to corresponding branches. When 
     890:obj:`branch_selector` and assign examples to corresponding branches. When 
    889891the value is unknown they choose a particular branch or simply skip 
    890892the example. 
     
    917919         
    918920        Use the information in :obj:`node` (particularly the 
    919         :obj:`branchSelector`) to split the given set of examples into 
     921        :obj:`branch_selector`) to split the given set of examples into 
    920922        subsets.  Return a tuple with a list of example generators and 
    921923        a list of weights.  The list of weights is either an ordinary 
     
    10611063classifiers, branch selectors, ...  as the original tree. Thus, you may 
    10621064modify a pruned tree structure (manually cut it, add new nodes, replace 
    1063 components) but modifying, for instance, some node's :obj:`nodeClassifier` 
    1064 (a :obj:`nodeClassifier` itself, not a reference to it!) would modify 
    1065 the node's :obj:`nodeClassifier` in the corresponding node of the 
     1065components) but modifying, for instance, some node's :obj:`node_classifier` 
     1066(a :obj:`node_classifier` itself, not a reference to it!) would modify 
     1067the node's :obj:`node_classifier` in the corresponding node of the 
    10661068original tree. 
    10671069 
    1068 Pruners cannot construct a :obj:`nodeClassifier` nor merge 
    1069 :obj:`nodeClassifier` of the pruned subtrees into classifiers for new 
     1070Pruners cannot construct a :obj:`node_classifier` nor merge 
     1071:obj:`node_classifier` of the pruned subtrees into classifiers for new 
    10701072leaves. Thus, if you want to build a prunable tree, internal nodes 
    1071 must have their :obj:`nodeClassifier` defined. Fortunately, this is 
     1073must have their :obj:`node_classifier` defined. Fortunately, this is 
    10721074the default. 
    10731075 
     
    10961098 
    10971099    This pruner will only prune the nodes in which the node classifier  
    1098     is of class :obj:`orange.DefaultClassifier` (or from a derived class). 
     1100    is of class :obj:`Orange.classification.ConstantClassifier`  
     1101    (or from a derived class). 
    10991102 
    11001103    Note that the leaves with more than one majority class require some  
     
    12471250the node:: 
    12481251 
    1249     >>> print tree.dump(leafStr="%V (%M out of %N)") 
     1252    >>> print tree.dump(leaf_str="%V (%M out of %N)") 
    12501253    petal width<0.800: Iris-setosa (50.000 out of 50.000) 
    12511254    petal width>=0.800 
     
    12611264with this:: 
    12621265 
    1263     >>> print tree.dump(leafStr="%V (%^MbA%, %^MbP%)") 
     1266    >>> print tree.dump(leaf_str="%V (%^MbA%, %^MbP%)") 
    12641267    petal width<0.800: Iris-setosa (100%, 100%) 
    12651268    petal width>=0.800 
     
    13211324 
    13221325What is the order of numbers here? If you check  
    1323 :samp:`data.domain.classVar.values` , you'll learn that the order is setosa,  
     1326:samp:`data.domain.class_var.values` , you'll learn that the order is setosa,  
    13241327versicolor, virginica; so in the node at peta length<5.350 we have 49 
    13251328versicolors and 3 virginicae. To print out the proportions, we can 
     
    13421345:: 
    13431346 
    1344     tree.dump(leafStr="%V", nodeStr=".") 
     1347    tree.dump(leaf_str="%V", node_str=".") 
    13451348     
    1346 says that the nodeStr should be the same as leafStr (not very useful  
    1347 here, since leafStr is trivial anyway). 
     1349says that the node_str should be the same as leaf_str (not very useful  
     1350here, since leaf_str is trivial anyway). 
    13481351 
    13491352::  
     
    13661369of virginicas decreases down the tree:: 
    13671370 
    1368     print tree.dump(leafStr='%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', nodeStr='.') 
     1371    print tree.dump(leaf_str='%^.1CbA="Iris-virginica"% (%^.1CbP="Iris-virginica"%)', node_str='.') 
    13691372 
    13701373Let's first interpret the format string: :samp:`CbA="Iris-virginica"` is  
     
    14011404:: 
    14021405 
    1403     >>> print tree.dump(leafStr='"%V   %D %.2DbP %.2dbP"', nodeStr='"%D %.2DbP %.2dbP"') 
     1406    >>> print tree.dump(leaf_str='"%V   %D %.2DbP %.2dbP"', node_str='"%D %.2DbP %.2dbP"') 
    14041407    root: [50.000, 50.000, 50.000] . . 
    14051408    |    petal width<0.800: [50.000, 0.000, 0.000] [1.00, 0.00, 0.00] [3.00, 0.00, 0.00]: 
     
    14391442the 90% confidence intervals in the leaves:: 
    14401443 
    1441     >>> print tree.dump(leafStr="[SE: %E]\t %V %I(90)", nodeStr="[SE: %E]") 
     1444    >>> print tree.dump(leaf_str="[SE: %E]\t %V %I(90)", node_str="[SE: %E]") 
    14421445    root: [SE: 0.409] 
    14431446    |    RM<6.941: [SE: 0.306] 
     
    14671470:samp:`%A` the average? Doesn't a regression tree always predict the 
    14681471leaf average anyway? Not necessarily, the tree predict whatever the 
    1469 :attr:`TreeClassifier.nodeClassifier` in a leaf returns.  
     1472:attr:`TreeClassifier.node_classifier` in a leaf returns.  
    14701473As :samp:`%V` uses the :obj:`Orange.data.variable.Continuous`' function 
    14711474for printing out the value, therefore the printed number has the same 
     
    14781481this number with values in the parent nodes:: 
    14791482 
    1480     >>> print tree.dump(leafStr="%C<22 (%cbP<22)", nodeStr=".") 
     1483    >>> print tree.dump(leaf_str="%C<22 (%cbP<22)", node_str=".") 
    14811484    root: 277.000 (.) 
    14821485    |    RM<6.941: 273.000 (1.160) 
     
    15051508:: 
    15061509 
    1507     >>> print tree.dump(leafStr="%C![20,22] (%^cbP![20,22]%)", nodeStr=".") 
     1510    >>> print tree.dump(leaf_str="%C![20,22] (%^cbP![20,22]%)", node_str=".") 
    15081511 
    15091512OK, let's observe the format string for one last time. :samp:`%c![20, 
     
    15351538------------------------------------ 
    15361539 
    1537 :meth:`TreeClassifier.dump`'s argument :obj:`userFormats` can be used to print out 
     1540:meth:`TreeClassifier.dump`'s argument :obj:`user_formats` can be used to print out 
    15381541some other information in the leaves or nodes. If provided, 
    1539 :obj:`userFormats` should contain a list of tuples with a regular 
     1542:obj:`user_formats` should contain a list of tuples with a regular 
    15401543expression and a callback function to be called when that expression 
    1541 is found in the format string. Expressions from :obj:`userFormats` 
     1544is found in the format string. Expressions from :obj:`user_formats` 
    15421545are checked before the built-in expressions discussed above, so you can 
    15431546override the built-ins if you want to. 
     
    15451548The regular expression should describe a string like those we used above, 
    15461549for instance the string :samp:`%.2DbP`. When a leaf or internal node 
    1547 is printed out, the format string (:obj:`leafStr` or :obj:`nodeStr`) 
     1550is printed out, the format string (:obj:`leaf_str` or :obj:`node_str`) 
    15481551is checked for these regular expressions and when the match is found, 
    15491552the corresponding callback function is called. 
    15501553 
    15511554The callback function will get five arguments: the format string  
    1552 (:obj:`leafStr` or :obj:`nodeStr`), the match object, the node which is 
     1555(:obj:`leaf_str` or :obj:`node_str`), the match object, the node which is 
    15531556being printed, its parent (can be None) and the tree classifier. 
    15541557The function should return the format string in which the part described 
     
    15831586 
    15841587    def replaceV(strg, mo, node, parent, tree): 
    1585         return insertStr(strg, mo, str(node.nodeClassifier.defaultValue)) 
     1588        return insertStr(strg, mo, str(node.node_classifier.default_value)) 
    15861589 
    15871590It therefore takes the value predicted at the node 
    1588 (:samp:`node.nodeClassifier.defaultValue` ), converts it to a string 
     1591(:samp:`node.node_classifier.default_value` ), converts it to a string 
    15891592and passes it to *insertStr* to do the replacement. 
    15901593 
     
    17271730    Quinlan's C4.5 code. 
    17281731 
    1729     .. attribute:: nodeType 
     1732    .. attribute:: node_type 
    17301733 
    17311734        Type of the node:  :obj:`C45Node.Leaf` (0),  
     
    17461749        Number of (learning) examples in the node. 
    17471750 
    1748     .. attribute:: classDist 
     1751    .. attribute:: class_dist 
    17491752 
    17501753        Class distribution for the node (of type  
    1751         :obj:`orange.DiscDistribution`). 
     1754        :obj:`Orange.statistics.distribution.Discrete`). 
    17521755 
    17531756    .. attribute:: tested 
     
    18141817in :samp:`node.leaf`. Since this is not a qualified value (ie.,  
    18151818:obj:`C45Node` does not know to which attribute it belongs), we need to 
    1816 convert it to a string through :obj:`classVar`, which is passed as an 
     1819convert it to a string through :obj:`class_var`, which is passed as an 
    18171820extra argument to the recursive part of printTree. 
    18181821 
     
    20652068 
    20662069        """ 
    2067         return  _c45_printTree0(self.tree, self.classVar, 0) 
     2070        return  _c45_printTree0(self.tree, self.class_var, 0) 
    20682071 
    20692072def _c45_showBranch(node, classvar, lev, i): 
    20702073    var = node.tested 
    20712074    str_ = "" 
    2072     if node.nodeType == 1: 
     2075    if node.node_type == 1: 
    20732076        str_ += "\n"+"|   "*lev + "%s = %s:" % (var.name, var.values[i]) 
    20742077        str_ += _c45_printTree0(node.branch[i], classvar, lev+1) 
    2075     elif node.nodeType == 2: 
     2078    elif node.node_type == 2: 
    20762079        str_ += "\n"+"|   "*lev + "%s %s %.1f:" % (var.name, ["<=", ">"][i], node.cut) 
    20772080        str_ += _c45_printTree0(node.branch[i], classvar, lev+1) 
     
    20902093    var = node.tested 
    20912094    str_ = "" 
    2092     if node.nodeType == 0: 
     2095    if node.node_type == 0: 
    20932096        str_ += "%s (%.1f)" % (classvar.values[int(node.leaf)], node.items)  
    20942097    else: 
    20952098        for i, branch in enumerate(node.branch): 
    2096             if not branch.nodeType: 
     2099            if not branch.node_type: 
    20972100                str_ += _c45_showBranch(node, classvar, lev, i) 
    20982101        for i, branch in enumerate(node.branch): 
    2099             if branch.nodeType: 
     2102            if branch.node_type: 
    21002103                str_ += _c45_showBranch(node, classvar, lev, i) 
    21012104    return str_ 
    21022105 
    21032106def _printTreeC45(tree): 
    2104     print _c45_printTree0(tree.tree, tree.classVar, 0) 
     2107    print _c45_printTree0(tree.tree, tree.class_var, 0) 
    21052108 
    21062109 
     
    21192122    of :class:`TreeClassifier` object is returned instead. 
    21202123 
    2121     The values of attributes can be also be set in the constructor.  
    2122  
    2123     .. attribute:: nodeLearner 
     2124    Attributes can be also be set in the constructor.  
     2125 
     2126    .. attribute:: node_learner 
    21242127 
    21252128        Induces a classifier from examples belonging to a node. The 
    21262129        same learner is used for internal nodes and for leaves. The 
    2127         default :obj:`nodeLearner` is :obj:`Orange.classification.majority.MajorityLearner`. 
     2130        default is :obj:`Orange.classification.majority.MajorityLearner`. 
    21282131 
    21292132    **Split construction** 
     
    21372140        affect the procedures for growing of the tree are ignored. These 
    21382141        include :obj:`binarization`, :obj:`measure`, 
    2139         :obj:`worstAcceptable` and :obj:`minSubset` (Default: 
     2142        :obj:`worst_acceptable` and :obj:`min_subset` (Default: 
    21402143        :class:SplitConstructor_Combined  
    21412144        with separate constructors for discrete and continuous attributes. 
     
    21642167        "retis" (:class:`Orange.feature.scoring.MSE`). Default: "gainRatio". 
    21652168 
    2166     .. attribute:: reliefM, reliefK 
     2169    .. attribute:: relief_m, relief_k 
    21672170 
    21682171        Sem `m` and `k` to given values if the :obj:`measure` is relief. 
     
    21772180    **Pruning** 
    21782181 
    2179     .. attribute:: worstAcceptable 
     2182    .. attribute:: worst_acceptable 
    21802183 
    21812184        Used in pre-pruning, sets the lowest required attribute 
     
    21832186        tree at that node is not grown further (default: 0). 
    21842187 
    2185         So, to allow splitting only when gainRatio (the default measure) 
    2186         is greater than 0.6, set :samp:`worstAcceptable=0.6`. 
    2187  
    2188     .. attribute:: minSubset 
     2188        So, to allow splitting only when gain ratio (the default measure) 
     2189        is greater than 0.6, set :samp:`worst_acceptable=0.6`. 
     2190 
     2191    .. attribute:: min_subset 
    21892192 
    21902193        Minimal number of examples in non-null leaves (default: 0). 
    21912194 
    2192     .. attribute:: minExamples 
    2193  
    2194         Data subsets with less than :obj:`minExamples` 
     2195    .. attribute:: min_examples 
     2196 
     2197        Data subsets with less than :obj:`min_examples` 
    21952198        examples are not split any further, that is, all leaves in the tree 
    21962199        will contain at least that many of examples (default: 0). 
    21972200 
    2198     .. attribute:: maxDepth 
     2201    .. attribute:: max_depth 
    21992202 
    22002203        Gives maximal tree depth;  0 means that only root is generated.  
    22012204        The default is 100.  
    22022205 
    2203     .. attribute:: maxMajority 
     2206    .. attribute:: max_majority 
    22042207 
    22052208        Induction stops when the proportion of majority class in the 
    22062209        node exceeds the value set by this parameter(default: 1.0).  
    22072210        To stop the induction as soon as the majority class reaches 70%, 
    2208         you should use :samp:`maxMajority=0.7`, as in the following 
     2211        you should use :samp:`max_majority=0.7`, as in the following 
    22092212        example. The numbers show the majority class  
    22102213        proportion at each node. The script `tree2.py`_ induces and  
     
    22272230        tree induction algorithms. See a documentation on  
    22282231        :class:`StopCriteria` for more info on this function.  
    2229         When used, parameters  :obj:`maxMajority` and :obj:`minExamples`  
     2232        When used, parameters  :obj:`max_majority` and :obj:`min_examples`  
    22302233        will not be  considered (default: None).  
    22312234        The default stopping criterion stops induction when all examples  
     
    22462249    **Record keeping** 
    22472250 
    2248     .. attribute:: storeDistributions, storeContingencies, storeExamples, storeNodeClassifier 
     2251    .. attribute:: store_distributions, store_contingencies, store_examples, store_node_classifier 
    22492252 
    22502253        Determines whether to store class distributions, contingencies and 
    2251         examples in :class:`Node`, and whether the :obj:`nodeClassifier` 
     2254        examples in :class:`Node`, and whether the :obj:`node_classifier` 
    22522255        should be build for internal nodes. By default everything except  
    2253         :obj:`storeExamples` is enabled. You won't save any memory by not storing  
     2256        :obj:`store_examples` is enabled. You won't save any memory by not storing  
    22542257        distributions but storing contingencies, since distributions actually points to 
    22552258        the same distribution that is stored in 
    22562259        :obj:`contingency.classes`. (default: True except for 
    2257         storeExamples, which defaults to False). 
     2260        store_examples, which defaults to False). 
    22582261     
    22592262    """ 
     
    22962299        if not self._handset_split and not self.measure: 
    22972300            measure = fscoring.GainRatio() \ 
    2298                 if examples.domain.classVar.varType == Orange.data.Type.Discrete \ 
     2301                if examples.domain.class_var.var_type == Orange.data.Type.Discrete \ 
    22992302                else fscoring.MSE() 
    2300             bl.split.continuousSplitConstructor.measure = measure 
    2301             bl.split.discreteSplitConstructor.measure = measure 
     2303            bl.split.continuous_split_constructor.measure = measure 
     2304            bl.split.discrete_split_constructor.measure = measure 
    23022305          
    23032306        if self.splitter != None: 
     
    23482351        """ 
    23492352        split = SplitConstructor_Combined() 
    2350         split.continuousSplitConstructor = \ 
     2353        split.continuous_split_constructor = \ 
    23512354            SplitConstructor_Threshold() 
    23522355        binarization = getattr(self, "binarization", 0) 
    23532356        if binarization == 1: 
    2354             split.discreteSplitConstructor = \ 
     2357            split.discrete_split_constructor = \ 
    23552358                SplitConstructor_ExhaustiveBinary() 
    23562359        elif binarization == 2: 
    2357             split.discreteSplitConstructor = \ 
     2360            split.discrete_split_constructor = \ 
    23582361                SplitConstructor_OneAgainstOthers() 
    23592362        else: 
    2360             split.discreteSplitConstructor = \ 
     2363            split.discrete_split_constructor = \ 
    23612364                SplitConstructor_Feature() 
    23622365 
     
    23752378 
    23762379        measureIsRelief = isinstance(measure, fscoring.Relief) 
    2377         relM = getattr(self, "reliefM", None) 
     2380        relM = getattr(self, "relief_m", None) 
    23782381        if relM and measureIsRelief: 
    23792382            measure.m = relM 
    23802383         
    2381         relK = getattr(self, "reliefK", None) 
     2384        relK = getattr(self, "relief_k", None) 
    23822385        if relK and measureIsRelief: 
    23832386            measure.k = relK 
    23842387 
    2385         split.continuousSplitConstructor.measure = measure 
    2386         split.discreteSplitConstructor.measure = measure 
    2387  
    2388         wa = getattr(self, "worstAcceptable", 0) 
     2388        split.continuous_split_constructor.measure = measure 
     2389        split.discrete_split_constructor.measure = measure 
     2390 
     2391        wa = getattr(self, "worst_acceptable", 0) 
    23892392        if wa: 
    2390             split.continuousSplitConstructor.worstAcceptable = wa 
    2391             split.discreteSplitConstructor.worstAcceptable = wa 
    2392  
    2393         ms = getattr(self, "minSubset", 0) 
     2393            split.continuous_split_constructor.worst_acceptable = wa 
     2394            split.discrete_split_constructor.worst_acceptable = wa 
     2395 
     2396        ms = getattr(self, "min_subset", 0) 
    23942397        if ms: 
    2395             split.continuousSplitConstructor.minSubset = ms 
    2396             split.discreteSplitConstructor.minSubset = ms 
     2398            split.continuous_split_constructor.min_subset = ms 
     2399            split.discrete_split_constructor.min_subset = ms 
    23972400 
    23982401        return split 
     
    24032406        """ 
    24042407        stop = Orange.classification.tree.StopCriteria_common() 
    2405         mm = getattr(self, "maxMajority", 1.0) 
     2408        mm = getattr(self, "max_majority", 1.0) 
    24062409        if mm < 1.0: 
    2407             stop.maxMajority = self.maxMajority 
    2408         me = getattr(self, "minExamples", 0) 
     2410            stop.max_majority = self.max_majority 
     2411        me = getattr(self, "min_examples", 0) 
    24092412        if me: 
    2410             stop.minExamples = self.minExamples 
     2413            stop.min_examples = self.min_examples 
    24112414        return stop 
    24122415 
     
    24172420        learner.stop = self.stop 
    24182421 
    2419         for a in ["storeDistributions", "storeContingencies", "storeExamples",  
    2420             "storeNodeClassifier", "nodeLearner", "maxDepth"]: 
     2422        for a in ["store_distributions", "store_contingencies", "store_examples",  
     2423            "store_node_classifier", "node_learner", "max_depth"]: 
    24212424            if hasattr(self, a): 
    24222425                setattr(learner, a, getattr(self, a)) 
     
    24252428 
    24262429    _built_fn = {  
    2427             "split": [ _build_split, [ "binarization", "measure", "reliefM", "reliefK", "worstAcceptable", "minSubset" ] ], \ 
    2428             "stop": [ _build_stop, ["maxMajority", "minExamples" ] ]  
     2430            "split": [ _build_split, [ "binarization", "measure", "relief_m", "relief_k", "worst_acceptable", "min_subset" ] ], \ 
     2431            "stop": [ _build_stop, ["max_majority", "min_examples" ] ]  
    24292432        } 
    24302433 
     
    24332436TreeLearner = Orange.misc.deprecated_members({ 
    24342437          "mForPruning": "m_pruning", 
    2435           "sameMajorityPruning": "same_majority_pruning" 
     2438          "sameMajorityPruning": "same_majority_pruning", 
     2439          "reliefM": "relief_m", 
     2440          "reliefK": "relief_k", 
     2441          "storeDistributions": "store_distributions", 
     2442          "storeContingencies": "store_contingencies", 
     2443          "storeExamples": "store_examples", 
     2444          "storeNodeClassifier": "store_node_classifier", 
     2445          "worstAcceptable": "worst_acceptable", 
     2446          "minSubset": "min_subset", 
     2447          "maxMajority": "max_majority", 
     2448          "minExamples": "min_examples", 
     2449          "maxDepth": "max_depth", 
     2450          "nodeLearner": "node_learner" 
    24362451}, wrap_methods=[])(TreeLearner) 
    24372452 
     
    25102525 
    25112526def replaceV(strg, mo, node, parent, tree): 
    2512     return insertStr(strg, mo, str(node.nodeClassifier.defaultValue)) 
     2527    return insertStr(strg, mo, str(node.node_classifier.default_value)) 
    25132528 
    25142529def replaceN(strg, mo, node, parent, tree): 
     
    25272542def replaceM(strg, mo, node, parent, tree): 
    25282543    by = mo.group("by") 
    2529     maj = int(node.nodeClassifier.defaultValue) 
     2544    maj = int(node.node_classifier.default_value) 
    25302545    N = node.distribution[maj] 
    25312546    if by: 
     
    25412556def replacem(strg, mo, node, parent, tree): 
    25422557    by = mo.group("by") 
    2543     maj = int(node.nodeClassifier.defaultValue) 
     2558    maj = int(node.node_classifier.default_value) 
    25442559    if node.distribution.abs > 1e-30: 
    25452560        N = node.distribution[maj] / node.distribution.abs 
     
    25572572 
    25582573def replaceCdisc(strg, mo, node, parent, tree): 
    2559     if tree.classVar.varType != Orange.data.Type.Discrete: 
     2574    if tree.class_var.var_type != Orange.data.Type.Discrete: 
    25602575        return insertDot(strg, mo) 
    25612576     
     
    25752590     
    25762591def replacecdisc(strg, mo, node, parent, tree): 
    2577     if tree.classVar.varType != Orange.data.Type.Discrete: 
     2592    if tree.class_var.var_type != Orange.data.Type.Discrete: 
    25782593        return insertDot(strg, mo) 
    25792594     
     
    25972612 
    25982613def replaceCcont(strg, mo, node, parent, tree): 
    2599     if tree.classVar.varType != Orange.data.Type.Continuous: 
     2614    if tree.class_var.var_type != Orange.data.Type.Continuous: 
    26002615        return insertDot(strg, mo) 
    26012616     
     
    26172632     
    26182633def replaceccont(strg, mo, node, parent, tree): 
    2619     if tree.classVar.varType != Orange.data.Type.Continuous: 
     2634    if tree.class_var.var_type != Orange.data.Type.Continuous: 
    26202635        return insertDot(strg, mo) 
    26212636     
     
    26512666     
    26522667def replaceCconti(strg, mo, node, parent, tree): 
    2653     if tree.classVar.varType != Orange.data.Type.Continuous: 
     2668    if tree.class_var.var_type != Orange.data.Type.Continuous: 
    26542669        return insertDot(strg, mo) 
    26552670 
     
    26692684             
    26702685def replacecconti(strg, mo, node, parent, tree): 
    2671     if tree.classVar.varType != Orange.data.Type.Continuous: 
     2686    if tree.class_var.var_type != Orange.data.Type.Continuous: 
    26722687        return insertDot(strg, mo) 
    26732688 
     
    26912706     
    26922707def replaceD(strg, mo, node, parent, tree): 
    2693     if tree.classVar.varType != Orange.data.Type.Discrete: 
     2708    if tree.class_var.var_type != Orange.data.Type.Discrete: 
    26942709        return insertDot(strg, mo) 
    26952710 
     
    27102725 
    27112726def replaced(strg, mo, node, parent, tree): 
    2712     if tree.classVar.varType != Orange.data.Type.Discrete: 
     2727    if tree.class_var.var_type != Orange.data.Type.Discrete: 
    27132728        return insertDot(strg, mo) 
    27142729 
     
    27322747 
    27332748def replaceAE(strg, mo, node, parent, tree): 
    2734     if tree.classVar.varType != Orange.data.Type.Continuous: 
     2749    if tree.class_var.var_type != Orange.data.Type.Continuous: 
    27352750        return insertDot(strg, mo) 
    27362751 
     
    27612776 
    27622777def replaceI(strg, mo, node, parent, tree): 
    2763     if tree.classVar.varType != Orange.data.Type.Continuous: 
     2778    if tree.class_var.var_type != Orange.data.Type.Continuous: 
    27642779        return insertDot(strg, mo) 
    27652780 
     
    28032818            self.leafStr = leafStr 
    28042819        else: 
    2805             if self.node().node_classifier.classVar.varType == \ 
     2820            if self.node().node_classifier.class_var.var_type == \ 
    28062821                    Orange.data.Type.Discrete: 
    28072822                self.leafStr = "%V (%^.2m%)" 
     
    28382853 
    28392854    def showBranch(self, node, parent, lev, i): 
    2840         bdes = node.branchDescriptions[i] 
    2841         bdes = node.branchSelector.classVar.name + \ 
     2855        bdes = node.branch_descriptions[i] 
     2856        bdes = node.branch_selector.class_var.name + \ 
    28422857            (bdes[0] not in "<=>" and "=" or "") + bdes 
    28432858        if node.branches[i]: 
     
    29072922                return 
    29082923                 
    2909             label = node.branchSelector.classVar.name 
     2924            label = node.branch_selector.class_var.name 
    29102925            if self.nodeStr: 
    29112926                label += "\\n" + self.formatString(self.nodeStr, node, parent) 
     
    29192934                        (_quoteName(internalName),  
    29202935                         _quoteName(internalBranchName),  
    2921                          node.branchDescriptions[i])) 
     2936                         node.branch_descriptions[i])) 
    29222937                    self.dotTree0(branch, node, internalBranchName) 
    29232938                     
     
    29742989        return self.dump() 
    29752990 
    2976     def dump(self, leafStr = "", nodeStr = "", **argkw):   
     2991    @Orange.misc.deprecated_keywords({"fileName": "file_name", \ 
     2992        "leafStr": "leaf_str", "nodeStr": "node_str", \ 
     2993        "userFormats": "user_formats", "minExamples": "min_examples", \ 
     2994        "maxDepth": "max_depth", "simpleFirst": "simple_first"}) 
     2995    def dump(self, leaf_str = "", node_str = "", \ 
     2996            user_formats=[], min_examples=0, max_depth=1e10, \ 
     2997            simple_first=True): 
    29772998        """ 
    29782999        Return a string representation of a tree. 
    29793000 
    2980         :arg leafStr: The format string for printing the tree leaves. If  
     3001        :arg leaf_str: The format string for printing the tree leaves. If  
    29813002          left empty, "%V (%^.2m%)" will be used for classification trees 
    29823003          and "%V" for regression trees. 
    2983         :type leafStr: string 
    2984         :arg nodeStr: The format string for printing out the internal nodes. 
     3004        :type leaf_str: string 
     3005        :arg node_str: The format string for printing out the internal nodes. 
    29853006          If left empty (as it is by default), no data is printed out for 
    29863007          internal nodes. If set to :samp:`"."`, the same string is 
    29873008          used as for leaves. 
    2988         :type nodeStr: string 
    2989         :arg maxDepth: If set, it limits the depth to which the tree is 
     3009        :type node_str: string 
     3010        :arg max_depth: If set, it limits the depth to which the tree is 
    29903011          printed out. 
    2991         :type maxDepth: integer 
    2992         :arg minExamples: If set, the subtrees with less than the given  
     3012        :type max_depth: integer 
     3013        :arg min_examples: If set, the subtrees with less than the given  
    29933014          number of examples are not printed. 
    2994         :type minExamples: integer 
    2995         :arg simpleFirst: If True (default), the branches with a single  
     3015        :type min_examples: integer 
     3016        :arg simple_first: If True (default), the branches with a single  
    29963017          node are printed before the branches with larger subtrees.  
    29973018          If False, the branches are printed in order of 
    29983019          appearance. 
    2999         :type simpleFirst: boolean 
    3000         :arg userFormats: A list of regular expressions and callback  
     3020        :type simple_first: boolean 
     3021        :arg user_formats: A list of regular expressions and callback  
    30013022          function through which the user can print out other specific  
    30023023          information in the nodes. 
    30033024        """ 
    3004         return _TreeDumper(leafStr, nodeStr, argkw.get("userFormats", []) +  
    3005             _TreeDumper.defaultStringFormats, argkw.get("minExamples", 0),  
    3006             argkw.get("maxDepth", 1e10), argkw.get("simpleFirst", True), 
    3007             self).dumpTree() 
    3008  
    3009     def dot(self, fileName, leafStr = "", nodeStr = "", leafShape="plaintext", nodeShape="plaintext", **argkw): 
     3025        return _TreeDumper(leaf_str, node_str, user_formats +  
     3026            _TreeDumper.defaultStringFormats, min_examples,  
     3027            max_depth, simple_first, self).dumpTree() 
     3028 
     3029    @Orange.misc.deprecated_keywords({"fileName": "file_name", \ 
     3030        "leafStr": "leaf_str", "nodeStr": "node_str", \ 
     3031        "leafShape": "leaf_shape", "nodeShape": "node_shape", \ 
     3032        "userFormats": "user_formats", "minExamples": "min_examples", \ 
     3033        "maxDepth": "max_depth", "simpleFirst": "simple_first"}) 
     3034    def dot(self, fileName, leaf_str = "", node_str = "", \ 
     3035            leaf_shape="plaintext", node_shape="plaintext", \ 
     3036            user_formats=[], min_examples=0, max_depth=1e10, \ 
     3037            simple_first=True): 
    30103038        """ Print the tree to a file in a format used by  
    30113039        `GraphViz <http://www.research.att.com/sw/tools/graphviz>`_. 
     
    30143042        nodes and leaves of the tree: 
    30153043 
    3016         :param leafShape: Shape of the outline around leaves of the tree.  
     3044        :param leaf_shape: Shape of the outline around leaves of the tree.  
    30173045            If "plaintext", no outline is used (default: "plaintext"). 
    3018         :type leafShape: string 
    3019         :param internalNodeShape: Shape of the outline around internal nodes  
    3020             of the tree. If "plaintext", no outline is used (default: "box") 
    3021         :type leafShape: string 
     3046        :type leaf_shape: string 
     3047        :param node_shape: Shape of the outline around internal nodes  
     3048            of the tree. If "plaintext", no outline is used (default: "plaintext") 
     3049        :type node_shape: string 
    30223050 
    30233051        Check `Polygon-based Nodes <http://www.graphviz.org/doc/info/shapes.html>`_  
     
    30263054        fle = type(fileName) == str and open(fileName, "wt") or fileName 
    30273055 
    3028         _TreeDumper(leafStr, nodeStr, argkw.get("userFormats", []) +  
    3029             _TreeDumper.defaultStringFormats, argkw.get("minExamples", 0),  
    3030             argkw.get("maxDepth", 1e10), argkw.get("simpleFirst", True), self, 
    3031             leafShape=leafShape, nodeShape=nodeShape, fle=fle).dotTree() 
     3056        _TreeDumper(leaf_str, node_str, user_formats +  
     3057            _TreeDumper.defaultStringFormats, min_examples,  
     3058            max_depth, simple_first, self, 
     3059            leafShape=leaf_shape, nodeShape=node_shape, fle=fle).dotTree() 
    30323060 
    30333061    def count_nodes(self): 
  • orange/doc/Orange/rst/code/orngTree1.py

    r8042 r8148  
    22 
    33data = Orange.data.Table("iris") 
    4 tree = Orange.classification.tree.TreeLearner(data, maxDepth=3) 
     4tree = Orange.classification.tree.TreeLearner(data, max_depth=3) 
    55 
    66formats = ["", "%V (%M out of %N)", "%V (%^MbA%, %^MbP%)", 
     
    1010for format in formats: 
    1111    print '\n\n*** FORMAT: "%s"\n' % format 
    12     print tree.dump(leafStr=format) 
     12    print tree.dump(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(leafStr=fl, nodeStr=fn) 
     16    print tree.dump(leaf_str=fl, node_str=fn) 
    1717 
    1818 
    1919data = Orange.data.Table("housing") 
    20 tree = Orange.classification.tree.TreeLearner(data, maxDepth=3) 
     20tree = Orange.classification.tree.TreeLearner(data, max_depth=3) 
    2121formats = ["", "%V"] 
    2222for format in formats: 
    2323    print '\n\n*** FORMAT: "%s"\n' % format 
    24     print tree.dump(leafStr=format) 
     24    print tree.dump(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(leafStr=fl, nodeStr=fn) 
     28    print tree.dump(leaf_str=fl, node_str=fn) 
  • orange/doc/Orange/rst/code/orngTree2.py

    r8042 r8148  
    33 
    44data = Orange.data.Table("iris") 
    5 tree = Orange.classification.tree.TreeLearner(data, maxDepth=3) 
     5tree = Orange.classification.tree.TreeLearner(data, max_depth=3) 
    66 
    7 def getMargin(dist): 
     7def get_margin(dist): 
    88    if dist.abs < 1e-30: 
    99        return 0 
     
    1313 
    1414def replaceB(strg, mo, node, parent, tree): 
    15     margin = getMargin(node.distribution) 
     15    margin = get_margin(node.distribution) 
    1616 
    1717    by = mo.group("by") 
     
    1919        whom = Orange.classification.tree.byWhom(by, parent, tree) 
    2020        if whom and whom.distribution: 
    21             divMargin = getMargin(whom.distribution) 
    22             if divMargin > 1e-30: 
    23                 margin /= divMargin 
     21            div_margin = get_margin(whom.distribution) 
     22            if div_margin > 1e-30: 
     23                margin /= div_margin 
    2424            else: 
    2525                Orange.classification.tree.insertDot(strg, mo) 
     
    2828    return Orange.classification.tree.insertNum(strg, mo, margin) 
    2929     
    30 myFormat = [(re.compile("%"+Orange.classification.tree.fs 
     30my_format = [(re.compile("%"+Orange.classification.tree.fs 
    3131    +"B"+Orange.classification.tree.by), replaceB)] 
    3232             
    33 print tree.dump(leafStr="%V %^B% (%^3.2BbP%)", userFormats=myFormat) 
     33print tree.dump(leaf_str="%V %^B% (%^3.2BbP%)", user_formats=my_format) 
  • orange/doc/Orange/rst/code/tree2.py

    r7713 r8148  
    1111print "BIG TREE:" 
    1212tree1 = Orange.classification.tree.TreeLearner(data) 
    13 print tree1.dump(leafStr="%m", nodeStr=".") 
     13print tree1.dump(leaf_str="%m", node_str=".") 
    1414 
    1515print "\nPRE-PRUNED TREE:" 
    16 tree2 = Orange.classification.tree.TreeLearner(data, maxMajority=0.7) 
    17 print tree2.dump(leafStr="%m", nodeStr=".") 
     16tree2 = Orange.classification.tree.TreeLearner(data, max_majority=0.7) 
     17print tree2.dump(leaf_str="%m", node_str=".") 
  • orange/doc/Orange/rst/code/tree3.py

    r8042 r8148  
    1313 
    1414print "SOME RANDOMNESS IN STOPING:" 
    15 defStop = Orange.classification.tree.StopCriteria() 
    16 f = lambda examples, weightID, contingency: defStop(examples, weightID, contingency) or randint(1, 5) == 1 
     15def_stop = Orange.classification.tree.StopCriteria() 
     16f = lambda examples, weightID, contingency: def_stop(examples, weightID, contingency) or randint(1, 5) == 1 
    1717l = Orange.classification.tree.TreeLearner(data, stop=f) 
    1818print l.dump() 
  • orange/doc/Orange/rst/code/treelearner.py

    r8042 r8148  
    1515        return 
    1616 
    17     if node.branchSelector: 
    18         nodeDesc = node.branchSelector.classVar.name 
    19         nodeCont = node.distribution 
    20         print "\n" + "   "*level + "%s (%s)" % (nodeDesc, nodeCont), 
     17    if node.branch_selector: 
     18        node_desc = node.branch_selector.class_var.name 
     19        node_cont = node.distribution 
     20        print "\n" + "   "*level + "%s (%s)" % (node_desc, node_cont), 
    2121        for i in range(len(node.branches)): 
    22             print "\n" + "   "*level + ": %s" % node.branchDescriptions[i], 
     22            print "\n" + "   "*level + ": %s" % node.branch_descriptions[i], 
    2323            printTree0(node.branches[i], level+1) 
    2424    else: 
    25         nodeCont = node.distribution 
    26         majorClass = node.nodeClassifier.defaultValue 
    27         print "--> %s (%s) " % (majorClass, nodeCont), 
     25        node_cont = node.distribution 
     26        major_class = node.node_classifier.default_value 
     27        print "--> %s (%s) " % (major_class, node_cont), 
    2828 
    2929def printTree(x): 
     
    3636 
    3737learner.stop = Orange.classification.tree.StopCriteria_common() 
    38 print learner.stop.maxMajority, learner.stop.minExamples 
     38print learner.stop.max_majority, learner.stop.min_examples 
    3939 
    4040print "\n\nTree with minExamples = 5.0" 
    41 learner.stop.minExamples = 5.0 
     41learner.stop.min_examples = 5.0 
    4242tree = learner(data) 
    4343print tree.dump() 
    4444 
    4545print "\n\nTree with maxMajority = 0.5" 
    46 learner.stop.maxMajority = 0.5 
     46learner.stop.max_majority = 0.5 
    4747tree = learner(data) 
    4848print tree.dump() 
  • orange/doc/Orange/rst/code/treestructure.py

    r8042 r8148  
    88 
    99data = Orange.data.Table("lenses") 
    10 treeClassifier = Orange.classification.tree.TreeLearner(data) 
     10tree_classifier = Orange.classification.tree.TreeLearner(data) 
    1111 
    12 def treeSize(node): 
     12def tree_size(node): 
    1313    if not node: 
    1414        return 0 
    1515 
    1616    size = 1 
    17     if node.branchSelector: 
     17    if node.branch_selector: 
    1818        for branch in node.branches: 
    19             size += treeSize(branch) 
     19            size += tree_size(branch) 
    2020 
    2121    return size 
    2222 
    23 print "Tree size:", treeSize(treeClassifier.tree) 
     23print "Tree size:", tree_size(tree_classifier.tree) 
    2424 
    2525 
     
    2929        return 
    3030 
    31     if node.branchSelector: 
    32         nodeDesc = node.branchSelector.classVar.name 
    33         nodeCont = node.distribution 
    34         print "\n" + "   "*level + "%s (%s)" % (nodeDesc, nodeCont), 
     31    if node.branch_selector: 
     32        node_desc = node.branch_selector.class_var.name 
     33        node_cont = node.distribution 
     34        print "\n" + "   "*level + "%s (%s)" % (node_desc, node_cont), 
    3535        for i in range(len(node.branches)): 
    36             print "\n" + "   "*level + ": %s" % node.branchDescriptions[i], 
     36            print "\n" + "   "*level + ": %s" % node.branch_descriptions[i], 
    3737            printTree0(node.branches[i], level+1) 
    3838    else: 
    39         nodeCont = node.distribution 
    40         majorClass = node.nodeClassifier.defaultValue 
    41         print "--> %s (%s) " % (majorClass, nodeCont), 
     39        node_cont = node.distribution 
     40        major_class = node.node_classifier.default_value 
     41        print "--> %s (%s) " % (major_class, node_cont), 
    4242 
    43 def printTree(x): 
     43def print_tree(x): 
    4444    if isinstance(x, Orange.classification.tree.TreeClassifier): 
    45         printTree0(x.tree, 0) 
     45        print_tree0(x.tree, 0) 
    4646    elif isinstance(x, Orange.classification.tree.Node): 
    47         printTree0(x, 0) 
     47        print_tree0(x, 0) 
    4848    else: 
    4949        raise TypeError, "invalid parameter" 
    5050 
    5151print "\n\nUnpruned tree" 
    52 print treeClassifier.dump() 
     52print tree_classifier.dump() 
    5353 
    54 def cutTree(node, level): 
    55     if node and node.branchSelector: 
     54def cut_tree(node, level): 
     55    if node and node.branch_selector: 
    5656        if level: 
    5757            for branch in node.branches: 
    58                 cutTree(branch, level-1) 
     58                cut_tree(branch, level-1) 
    5959        else: 
    60             node.branchSelector = None 
     60            node.branch_selector = None 
    6161            node.branches = None 
    62             node.branchDescriptions = None 
     62            node.branch_descriptions = None 
    6363 
    6464print "\n\nPruned tree" 
    65 cutTree(treeClassifier.tree, 2) 
    66 print treeClassifier.dump() 
     65cut_tree(tree_classifier.tree, 2) 
     66print tree_classifier.dump() 
    6767 
Note: See TracChangeset for help on using the changeset viewer.