from numpy import *
def loadSimpData():
datMat = matrix([[1., 2.1],
[2., 1.1],
[1.3, 1.],
[1.1, 1.1],
[2., 1.]
])
classLabels = [1.0, 1.0, -1.0, -1.0, 1.0]
return datMat, classLabels
def stumpClassify(dataMatrix, dimen, threshVal, threshIneq): # 单层决策树模型
retArray = ones((shape(dataMatrix)[0], 1))
if threshIneq == 'lt': # 若threshVal == 'lt' 并且dataMatirx <= threshVal 则 labels 改为 -1
retArray[dataMatrix[:, dimen] <= threshVal] = -1.0
else:
retArray[dataMatrix[:, dimen] > threshVal] = -1.0
return retArray
def buildStump(dataArr, classLabels, D): # 遍历所有的数据,通过单层决策数对其进行分类
dataMatrix = mat(dataArr)
labelMat = mat(classLabels).T
m,n = shape(dataMatrix)
numSteps = 10.0; bestStump = {}; bestClasEst = mat(zeros((m, 1
Python实现adaboost 算法+简单的注释
最新推荐文章于 2024-03-24 11:41:07 发布