How should I write a tree using diconary. I have used a dictonary to
make a tree.
tree={best:collections.defaultdict(lambda:default)} in a id3 tree.
Is there a way to multple values and when then only return on type of
values.
I tried this apporach but it did not work.
class Tree:
def __init__(self):
pass
def ini(self,default_tree,d_attr):
self.tree={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_A={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_I={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_p={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_n={d_attr:collections.defaultdict(lambda:default_tree)}
return self.tree
def __call__(self,best,val,subtree):
self.tree[best][val]=subtree
def
input_tree(self,best,val,subtree,postive,negative,attribute_value,info_gain):
tree=self.tree
print best
print val
tree[best][val]=subtree
print self.tree
self.tree_A[best][val]= attribute_value
self.tree_I[best][val]= info_gain
self.tree_p[best][val]= postive
self.tree_n=negative
tree=self.tree
return tree
--
http://mail.python.org/mailman/listinfo/python-list