def calculateIG(self,groups,labels):
# current entropy
labelfracs = self.obtain_labelfracs(labels)
current_entropy = self.calculate_entropy(labelfracs)
# entropy of each grouping
group_entropy = []
for group in groups:
labelfracs = self.obtain_labelfracs(group)
group_entropy.append((len(group)/len(labels)) * self.calculate_entropy(labelfracs))
infogain = current_entropy - sum(group_entropy)
return infogain
评论列表
文章目录