from math import log def calcShannonEnt(dataSet): numEntries = len(dataSet) print("样本总数:" + str(numEntries)) labelCounts = {} #记录每一类标签的数量 #定义特征向量featVec for featVec in dataSet: currentLabel = featVec[-1] #最后一列是类别标签 if currentLabel not in labelCo…
from math import log import numpy as np import matplotlib.pyplot as plt import operator #计算给定数据集的香农熵 def calcShannonEnt(dataSet): numEntries = len(dataSet) labelCounts = {} for featVec in dataSet: #| currentLabel = featVec[-1] #| if currentLabel not…
机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理.源码解析及测试 关键字:决策树.python.源码解析.测试作者:米仓山下时间:2018-10-24机器学习实战(Machine Learning in Action,@author: Peter Harrington)源码下载地址:https://www.manning.com/books/machine-learning-in-actiongit@github.com:pbharrin/ma…