(dataSet,labels)
return myTree
构建决策树
    :param dataSet: 数据集样本
    :param labels: 特征属性
    :return: 决策树
构建决策树
    :param dataSet: 数据集样本
    :param labels: 特征属性
    :return: 决策树
构建决策树 : param dataSet : 数据集样本 : param labels : 特征属性 : return : 决策树
def createTree(dataSet,labels):
    '''
    构建决策树
    :param dataSet: 数据集样本
    :param labels: 特征属性
    :return: 决策树
    '''

    # 决策类别
    classList = [example[-1] for example in dataSet]
    # 类别完全相同停止继续划分
    if classList.count(classList[0]) == len(classList):
        return classList[0]
    # 返回出现次数最多的类别
    if len(dataSet[0]) == 1:
        return majorityCnt(classList)
    # 返回最优的特征属性
    bestFeature = chooseBestFeatureToSplit(dataSet)
    bestFeatLabel = labels[bestFeature]
    myTree = {bestFeatLabel:{}}
    del(labels[bestFeature])
    # 最优特征值
    featureValues = [example[bestFeature] for example in dataSet]
    uniqueVals = set(featureValues)
    for value in uniqueVals:
        subLabels = labels[:]
        myTree[bestFeatLabel][value] = createTree(splitDataSet(dataSet, bestFeature, value), subLabels)
    return myTree
def createTree ( dataSet , labels ) : # 决策类别 classList = [ example [ - 1 ] for example in dataSet ] # 类别完全相同停止继续划分 if classList . count ( classList [ 0 ] ) == len ( classList ) : return classList [ 0 ] # 返回出现次数最多的类别 if len ( dataSet [ 0 ] ) == 1 : return majorityCnt ( classList ) # 返回最优的特征属性 bestFeature = chooseBestFeatureToSplit ( dataSet ) bestFeatLabel = labels [ bestFeature ] myTree = { bestFeatLabel : { } } del ( labels [ bestFeature ] ) # 最优特征值 featureValues = [ example [ bestFeature ] for example in dataSet ] uniqueVals = set ( featureValues ) for value in uniqueVals : subLabels = labels [ : ] myTree [ bestFeatLabel ] [ value ] = createTree ( splitDataSet ( dataSet , bestFeature , value ) , subLabels ) return myTree