本文整理汇总了Python中TreeNode.TreeNode.addSubtree方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.addSubtree方法的具体用法?Python TreeNode.addSubtree怎么用?Python TreeNode.addSubtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode.TreeNode
的用法示例。
在下文中一共展示了TreeNode.addSubtree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decisionTreeLearning
# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import addSubtree [as 别名]
def decisionTreeLearning(examples, attribs, default):
if len(examples) == 0:
#if example list empty then return the majority value
#computed previously
return TreeNode(None, default)
elif checkIfSameClass(examples):
#if all examples same class then return the class
return TreeNode(None, examples[0].label)
elif len(attribs) == 0:
#if attributes empty then return majority value
return TreeNode(None, majorityValue(examples))
else:
bestAttrib = chooseAttribute(attribs, examples)
tree = TreeNode(bestAttrib)
majorityVal = majorityValue(examples)
#for each possible value of attribute
for attribVal in Attribute.getAttributes()[bestAttrib]:
filteredExamples = filterExamples(bestAttrib, attribVal, examples)
subTree = decisionTreeLearning(filteredExamples, \
filterAttributes(attribs, bestAttrib), majorityVal)
tree.addSubtree(attribVal, subTree)
return tree