-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathorngTree2.py
33 lines (27 loc) · 1.03 KB
/
orngTree2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Orange
import re
iris = Orange.data.Table("iris")
tree = Orange.classification.tree.TreeLearner(iris, max_depth=3)
def get_margin(dist):
if dist.abs < 1e-30:
return 0
l = list(dist)
l.sort()
return (l[-1] - l[-2]) / dist.abs
def replaceB(strg, mo, node, parent, tree):
margin = get_margin(node.distribution)
by = mo.group("by")
if margin and by:
whom = Orange.classification.tree.by_whom(by, parent, tree)
if whom and whom.distribution:
div_margin = get_margin(whom.distribution)
if div_margin > 1e-30:
margin /= div_margin
else:
Orange.classification.tree.insert_dot(strg, mo)
else:
return Orange.classification.tree.insert_dot(strg, mo)
return Orange.classification.tree.insert_num(strg, mo, margin)
my_format = [(re.compile("%" + Orange.classification.tree.fs
+ "B" + Orange.classification.tree.by), replaceB)]
print tree.to_string(leaf_str="%V %^B% (%^3.2BbP%)", user_formats=my_format)