Machine Learning in Action ch.3.2 Tree (2) & 3.3 Tree
이제 전에 얻은 단말 노드의 갯수와 단계의 갯수로 트리 전체를 플롯할 수 있다. def getTreeDepth(myTree): maxDepth = 0 firstStr = myTree.keys() secondDict = myTree[firstStr] for key in secondDict.keys(): if type(secondDict[key]).__name__=='dict':#딕셔너리인지 아닌지 검사 thisDepth = 1 + getTreeDepth(secondDict[key]) else: thisDepth = 1 if thisDepth > maxDepth: maxDepth = thisDepth return maxDepth def plotMidText(cntrPt, parentPt, txtString): xMid = (parentPt[0]-cntrPt[0])/2.0 + cntrPt[0] yMid = (parentPt[1]-cntrPt[1])/2.0 + cntrPt[1] createPlot.ax1.text(xMid, yMid, txtString, va="center", ha="center", rotation=30) def plotTree(myTree, parentPt, nodeTxt):#if the first key tells you what feat was split on numLeafs = getNumLeafs(myTree) #this determines...