美文网首页
无标题文章

无标题文章

作者: 讳莫如深Jason | 来源:发表于2016-09-18 15:17 被阅读0次

'''

def chooseBestFeatureToSplit(dataSet):

numFeatures=len(dataSet[0])-1  #每组的特征值数量,去掉了最后的标签

baseEntropy=calcShannonEnt(dataSet) #计算数据集的原始香农熵

bestInfoGain=0.0;bestFeature =  -1

for i in range(numFeatures):

featList=[example[i] for example in dataSet] #相同位置的第i个特征值

uniqueVals=set(featList) #set(集合):获取list中所有不重复的元素值

newEntropy=0.0

for value in uniqueVals:

subDataSet=splitDataSet(dataSet,i,value)  #针对当前的value划分出新的数据集

prob=len(subDataSet)/float(len(dataSet))  #新数据集所占比例

newEntropy+=prob*calcShannonEnt(subDataSet) #这里用加权求和,求出新的熵值

infoGain=baseEntropy-newEntropy                #新旧相减,得到信息增益

if (infoGain>bestInfoGain):    #随着i的增加逐次进行减法,结果为正说明熵减,则infogain越大越好

bestInfoGain=infoGain

bestFeature=i              #逐次比较,得到最大的信息增益

return bestFeature

'''

相关文章

  • 无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章 无标题文章无标题文章无标题文章无...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • fasfsdfdf

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章 无标题文章 无标题文章无标题文章 无标题文章 无标题文章

网友评论

      本文标题:无标题文章

      本文链接:https://www.haomeiwen.com/subject/tgiwettx.html