source: orange/Orange/testing/regression/tests_20/modules_orngTree2.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 948 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line 
1import orange, orngTree, re
2reload(orngTree)
3
4data = orange.ExampleTable("iris")
5tree = orngTree.TreeLearner(data, maxDepth=3)
6
7def getMargin(dist):
8    if dist.abs < 1e-30:
9        return 0
10    l = list(dist)
11    l.sort()
12    return (l[-1] - l[-2]) / dist.abs
13
14def replaceB(strg, mo, node, parent, tree):
15    margin = getMargin(node.distribution)
16
17    by = mo.group("by")
18    if margin and by:
19        whom = orngTree.byWhom(by, parent, tree)
20        if whom and whom.distribution:
21            divMargin = getMargin(whom.distribution)
22            if divMargin > 1e-30:
23                margin /= divMargin
24            else:
25                orngTree.insertDot(strg, mo)
26        else:
27            return orngTree.insertDot(strg, mo)
28    return orngTree.insertNum(strg, mo, margin)
29
30
31   
32myFormat = [(re.compile("%"+orngTree.fs+"B"+orngTree.by), replaceB)]
33           
34orngTree.printTree(tree, leafStr="%V %^B% (%^3.2BbP%)", userFormats = myFormat)
Note: See TracBrowser for help on using the repository browser.