本文整理汇总了Python中tree.Node.add_branch方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_branch方法的具体用法?Python Node.add_branch怎么用?Python Node.add_branch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Node
的用法示例。
在下文中一共展示了Node.add_branch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grow_tree
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import add_branch [as 别名]
def grow_tree(records, attributes, default = ''):
if stopping_condition(records, attributes):
label = classify(records)
if label is None:
label = default
return Node(label = label)
else:
i, condition = find_best_split(records, attributes)
default = classify(records)
attributes[-1], attributes[i] = attributes[i], attributes[-1]
name, v, values = attributes.pop()
if v != False:
root = Node(label = name + '<=' + str(v), test = condition)
values = [True, False]
else:
root = Node(label = name, test = condition)
for value in values:
new_records = filter(lambda r: condition(r) == value, records)
child = grow_tree(new_records, attributes, default)
root.add_branch(value)
root.add_child(child)
attributes.append( (name, v, values) )
attributes[-1], attributes[i] = attributes[i], attributes[-1]
return root