def createtree(dataset,labels):
classlist = [example[-1] for example in dataset]
if classlist.count(classlist[0]) == len(classlist):#print(labels)
return classlist[0]
if len(dataset[0]) == 1:
return majorityCnt(classlist)
bestFeat = chooseBestFeatureToSplit(dataset)
bestFeatLabel = labels[bestFeat]
myTree = {bestFeatLabel:{}}
bestfeatvalues = [example[bestFeat] for example in dataset]
del[labels[bestFeat]]
uniqueVals = set(bestfeatvalues)
for value in bestfeatvalues:
sublabels = labels[:]
#print(sublabels)
myTree[bestFeatLabel][value] = createtree(splitDataSet(dataset,bestFeat,value),sublabels)
print(labels)
return myTree
这个是决策树的部分代码,源于机器学习实战,我在return的前加了print(labels),显示出来一共有8组标签,这是为社么啊,求大神告知,递归的话我找不出来这么多标签啊,求大神告知