import matplotlib.pyplot as plt
decisionNode = dict(boxstyle="sawtooth", fc="0.8")
leafNode = dict(boxstyle="round4", fc="0.8")
arrow_args = dict(arrowstyle="<-")
def retrieveTree(i):
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'}}}}
]
return listOfTrees[i]
#获取叶节点的数目和树的层数
def getNumLeafs(myTree):
numLeafs = 0
firstSide = list(myTree.keys())
firstStr = firstSide[0]
secondDict = myTree[firstStr]
for key in secondDict:
if type(secondDict[key]).__name__ == 'dict':
numLeafs += getNumLeafs(secondDict[key])
else:
numLeafs
matplotlib绘制树形图
最新推荐文章于 2024-06-17 15:12:48 发布