更新构建树的Coding

This commit is contained in:
jiangzhonglian
2017-03-06 21:13:32 +08:00
parent a778798dd8
commit 10e1c2b577
9 changed files with 569 additions and 55 deletions

View File

@@ -98,6 +98,7 @@ def show_pdf(clf):
# from IPython.display import Image
# Image(graph.create_png())
if __name__ == '__main__':
x, y = createDataSet()

View File

@@ -77,9 +77,9 @@ def plotTree(myTree, parentPt, nodeTxt):
plotTree.yOff = plotTree.yOff - 1.0/plotTree.totalD
for key in secondDict.keys():
# 判断该节点是否是Node节点
if type(secondDict[key]).__name__=='dict':
if type(secondDict[key]).__name__ == 'dict':
# 如果是就递归调用[recursion]
plotTree(secondDict[key],cntrPt,str(key))
plotTree(secondDict[key], cntrPt, str(key))
else:
# 如果不是,就在原来节点一半的地方找到节点的坐标
plotTree.xOff = plotTree.xOff + 1.0/plotTree.totalW
@@ -121,7 +121,7 @@ def createPlot(inTree):
# 测试数据集
def retrieveTree(i):
listOfTrees =[
listOfTrees = [
{'no surfacing': {0: 'no', 1: {'flippers': {0: 'no', 1: 'yes'}}}},
{'no surfacing': {0: 'no', 1: {'flippers': {0: {'head': {0: 'no', 1: 'yes'}}, 1: 'no'}}}}
]