第三章 3.1.1信息增益

第三章 3.1.1信息增益

2016-11-28    04'45''

主播: 叮宕

84 9

介绍:
from collections import Counter from math import log def calcShannonEnt(dataset): classCnt = [sample[-1] for sample in dataset] n = len(dataset) classCnt = Counter(classCnt) ent = 0. for times in classCnt.values(): ent -= times/n*log(times/n, 2) return ent