(dataSet)
return entropy
计算熵
    :param dataSet: 数据集
    :return: 熵值
计算熵
    :param dataSet: 数据集
    :return: 熵值
计算熵 : param dataSet : 数据集 : return : 熵值
def calcEntropy(dataSet):
    '''
    计算熵
    :param dataSet: 数据集
    :return: 熵值
    '''

    numEntries = len(dataSet)
    labelCounts = {}
    for line in dataSet:
        currentLabel = line[-1]
        if currentLabel not in labelCounts.keys():
            labelCounts[currentLabel] = 0
        labelCounts[currentLabel] += 1
    entropy = 0.0
    for key in labelCounts:
        prob = float(labelCounts[key]) / numEntries
        entropy -= prob * log(prob, 2)
    return entropy
def calcEntropy ( dataSet ) : numEntries = len ( dataSet ) labelCounts = { } for line in dataSet : currentLabel = line [ - 1 ] if currentLabel not in labelCounts . keys ( ) : labelCounts [ currentLabel ] = 0 labelCounts [ currentLabel ] += 1 entropy = 0.0 for key in labelCounts : prob = float ( labelCounts [ key ] ) / numEntries entropy -= prob * log ( prob , 2 ) return entropy