# -*-coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
'''
创建单层决策树的数据集
return:
dataMat---数据矩阵
classLabels---数据标签
'''
def loadSimpData():
dataMat = ([[1.0,2.1],
[1.5,1.6],
[1.3,1.0],
[1.0,1.0],
[2.0,1.0]
])
classLabels = [1.0,1.0,-1.0,-1.0,1.0]
return dataMat,classLabels
'''
单层决策树分类函数
parameter
dataMat-数据矩阵
dimen-第dimen列,即第几个特征
threshVal-阈值
threshIneq-标志
return:
retArray-分类结果
只是简单的将数据分为两类-1,1,初始化了一个全1的矩阵,我们判断一下阈值第i列小于/大于阈值的就为-1,
(因为我们并不清楚这个划分标准,所以要大于小于都试一次)每一个维度的所有数据跟阈值比较,就相当于找到
一个点(阈值)划分所有数据。
'''
def stumpClassify(dataMat,dimen,threshVal,threshIneq):
retArray = np.ones((np.shape(dataMat)[0],1)) #初始化为1
if threshIneq == 'lt':
retArray[dataMat[:,dimen] <= thr
机器学习实战之AdaBoost练习---python
最新推荐文章于 2022-10-29 15:00:00 发布