资源简介
Adaboost实战代码,利用决策树桩作为基弱分类器,并利用集成学习器进行病马死亡率的预测,得到了良好的预测效果。
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Fri Nov 9 15:01:36 2018
@author: zhe
E-mail: 1194585271@qq.com
“““
import numpy as np
def loadSimpData():
datMat = np.matrix([[ 1. 2.1]
[ 2. 1.1]
[ 1.3 1. ]
[ 1. 1. ]
[ 2. 1. ]])
classLabels = [1.0 1.0 -1.0 -1.0 1.0]
return datMatclassLabels
def stumpClassify(dataMatrixdimenthreshValthreshIneq):#just classify the data
retArray = np.ones((np.shape(dataMatrix)[0]1))
if threshIneq == ‘lt‘:
retArray[dataMatrix[:dimen] <= threshVal] = -1.0
else:
retArray[dataMatrix[:dimen] > threshVal] = -1.0
return retArray
def buildStump(dataArrclassLabelsD):
dataMatrix = np.mat(dataArr); labelMat = np.mat(classLabels).T
mn = np.shape(dataMatrix)
numSteps = 10.0; bestStump = {}; bestClasEst = np.mat(np.zeros((m1)))
minError = np.inf #init error sum to +infinity
for i in range(n):#loop over all dimensions
rangeMin = dataMatrix[:i].min(); rangeMax = dataMatrix[:i].max();
stepSize = (rangeMax-rangeMin)/numSteps
for j in range(-1int(numSteps)+1):#loop over all range in current dimension
for inequal in [‘lt‘ ‘gt‘]: #go over less than and greater than
threshVal = (rangeMin + float(j) * stepSize)
predictedVals = stumpClassify(dataMatrixithreshValinequal)#call stump classify with i j lessThan
errArr = np.mat(np.ones((m1)))
errArr[predictedVals == labelMat] = 0
weightedError = D.T*errArr #calc total error multiplied by D
print (‘split: dim %d thresh %.2f thresh ineqal: %s the weighted error is %.3f‘ %(i threshVal inequal weightedError))
if weightedError < minError:
minError = weightedError
bestClasEst = predictedVals.copy()
bestStump[‘dim‘] = i
bestStump[‘thresh‘] = threshVal
bestStump[‘ineq‘] = inequal
return bestStumpminErrorbestClasEst
if __name__==‘__main__‘:
datMatclassLabels = loadSimpData()
D = np.mat(np.ones((51))/5)
print (buildStump(datMatclassLabelsD))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-09 15:05 Chapter7_Adaboost\1.realizeWeakclassifer\
文件 2285 2018-11-09 15:24 Chapter7_Adaboost\1.realizeWeakclassifer\Adaboost.py
目录 0 2018-11-10 15:52 Chapter7_Adaboost\2.realizeAdaboost\
文件 5937 2018-11-10 16:44 Chapter7_Adaboost\2.realizeAdaboost\Adaboost.py
目录 0 2018-11-10 16:27 Chapter7_Adaboost\3.inAction\
文件 6166 2018-11-12 16:26 Chapter7_Adaboost\3.inAction\Adaboost.py
文件 13614 2010-12-06 08:29 Chapter7_Adaboost\3.inAction\horseColicTest2.txt
文件 60778 2010-12-06 08:26 Chapter7_Adaboost\3.inAction\horseColicTraining2.txt
- 上一篇:支持向量机实战代码全
- 下一篇:DHT11在linux上的驱动程序
相关资源
- 支持向量机实战代码全
- 浅析机器学习的研究与应用
- 2017年最新机器学习与深度学习从基础
- 机器学习课后习题答案(整理所有版
- Adaboost训练和测试代码
- CMU机器学习讲义
- 李宏毅机器学习中文课程全套视频
- 基于SVM的AdaBoost
- 一种基于AdaBoost的SVM分类器(1).pdf
- PRML模式识别与机器学习 习题答案完整
- libsvm-3.20.zip
- 基于tensorflow的猫狗图片的识别分类
- 漏洞推断-利用机器学习辅助发现漏洞
- 使用C5.0决策树识别高风险银行贷款
- 小象学习机器学习视频不知道哪期.
- 机器学习第七期升级版.docx
- 百度网盘链接coursera 吴恩达深度机器
- MachineLearning-相似度距离公式
- Spark机器学习回归模型数据集
- coursera吴恩达机器学习全套视频和文档
- 电机振动故障检测tensorflow神经网络
- Machine Learning Linear Regression-线性回归
- 疝气病数据集逻辑回归
- 17 机器学习案例——基于朴素贝叶斯
- spark机器学习简单文档
- 机器学习特征的的代码lpq
- 图解机器学习代码
- 南京大学周志华老师的一个讲普适机
- 最新版coursera吴恩达机器学习全套视频
- 吴恩达机器学习视频中英文字幕字幕
评论
共有 条评论