-
大小: 75KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-06-07
- 语言: Matlab
- 标签: knn adaboost adaboost.M1 matlab
资源简介
基于knn的adaboost.M1的实现 求分享
代码片段和文件信息
% adaboost.M1
function [trerr tserr w] = adaboostM1(fea_tr lab_tr fea_ts lab_tsMcnln)
% function [trerr tserr w] = adaboostM1(type fea_tr lab_tr fea_ts lab_ts M cnln)
% perform adaboost algorithm
% type: the based classifier
% fea_tr lab_tr: training feature and label
% fea_ts lab_ts: testing feature and label
% M: iteration num
% cn: class num
%
% trerr training error (combined)
% tserr testing error
% w weight distribution
if nargin < 6
disp(‘adaboostM1(type fea_tr lab_tr fea_ts lab_ts M [cn])‘);
return;
elseif nargin == 6
cn = 2;
end
if nargout < 3
w = [];
end
% first get parameters
vsize = size(fea_tr 1);
trnum = size(fea_tr 2);
tsnum = size(fea_ts 2);
%
if (vsize ~= size(fea_ts 1))
disp(‘training feature and testing feature donnot have same size\n‘);
return;
end
if (trnum ~= size(lab_tr 2))
disp(‘training set has different feature and label size\n‘);
return;
end
if (tsnum ~= size(lab_ts 2))
disp(‘testing set has different feature and label size\n‘);
return;
end
% deal with different base classifiers
% switch lower(type)
%
% case ‘nearest‘ % nearest neighbour
% parameters
weight = ones(1 trnum) / trnum;
alpha_M = zeros(1 M);
hypo_tr_M = zeros(1 trnum M);
I_tr_M = zeros(1 trnum M);
hypo_ts_M = zeros(1 tsnum M);
I_ts_M = zeros(1 tsnum M);
m = 1; err = -1;
while m<=M & err<0.5 & err~=0
% [fea_trfea_ts] = get_sample(ln);
% resample data
[fea_w lab_w idx_w] = resample(fea_tr lab_tr weight);
% train base classifier and run base classifier on ORIGINAL trainning data I==1 means wrongly classified
% for KNN it requires only one step
[I_tr hypo_tr] = knn(fea_w lab_w fea_tr lab_tr); % train on training set
[I_ts hypo_ts] = knn(fea_w lab_w fea_ts lab_ts); % train on testing set
% calculate err
err = sum(weight .* I_tr 2) / sum(weight 2);
% calculate alpha
alpha_M(m) = 0.5*log((1-err)/err);
% update weight
weight = weight .* exp(2*alpha_M(m)*I_tr);
weight = weight ./ sum(weight2);
% store parameters for round m
hypo_tr_M(: : m) = hypo_tr;
hypo_ts_M(: : m) = hypo_ts;
I_tr_M(: : m) = I_tr;
I_ts_M(: : m) = I_ts;
% update m
m = m + 1;
end
% show debug information
% disp(m);
% disp(alpha_M);
% combine all weak learners and output trainning error
tr_res = zeros(1 trnum);
for i = 1:trnum
v = zeros(1 cn);
for t = 1:m-1
if I_tr_M(: i t) == 0
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3889 2010-12-13 18:22 adaboost+knn+lbp\adaboost+knn+lbp\adaboostM1.m
文件 818 2010-12-15 14:43 adaboost+knn+lbp\adaboost+knn+lbp\EXP_1NN_ADA.m
文件 2030 2010-12-16 10:45 adaboost+knn+lbp\adaboost+knn+lbp\getLBPFea.m
文件 1298 2010-10-16 14:57 adaboost+knn+lbp\adaboost+knn+lbp\getLBPHist.m
文件 1764 2011-12-12 20:48 adaboost+knn+lbp\adaboost+knn+lbp\getLBPHists_tr.m
文件 1764 2011-12-12 20:49 adaboost+knn+lbp\adaboost+knn+lbp\getLBPHists_ts.m
文件 3385 2011-12-12 20:40 adaboost+knn+lbp\adaboost+knn+lbp\getMBLBPFea.m
文件 2531 2010-10-16 11:25 adaboost+knn+lbp\adaboost+knn+lbp\getMBLBPFea_33.m
文件 2378 2011-11-28 14:47 adaboost+knn+lbp\adaboost+knn+lbp\get_sample.m
文件 29270 2011-12-12 20:49 adaboost+knn+lbp\adaboost+knn+lbp\histLBPs_tr.mat
文件 29216 2011-12-12 20:49 adaboost+knn+lbp\adaboost+knn+lbp\histLBPs_ts.mat
文件 415 2010-10-14 23:58 adaboost+knn+lbp\adaboost+knn+lbp\IsUniform.m
文件 622 2010-12-08 09:56 adaboost+knn+lbp\adaboost+knn+lbp\knn.m
文件 290 2011-11-14 08:46 adaboost+knn+lbp\adaboost+knn+lbp\LBPMap.mat
文件 672 2010-12-16 11:03 adaboost+knn+lbp\adaboost+knn+lbp\makeLBPMap.m
文件 1253 2010-12-09 19:23 adaboost+knn+lbp\adaboost+knn+lbp\resample.m
文件 2092 2011-12-12 20:52 adaboost+knn+lbp\adaboost+knn+lbp\txn.m
文件 6660 2011-12-12 21:22 adaboost+knn+lbp\adaboost+knn+lbp\unti
文件 0 2012-03-03 11:26 adaboost+knn+lbp\trainData.txt
目录 0 2012-09-27 10:58 adaboost+knn+lbp\adaboost+knn+lbp
目录 0 2012-09-27 10:58 adaboost+knn+lbp
----------- --------- ---------- ----- ----
90347 21
相关资源
- adaboost详解及matlab
- KNN分类MatLAB源代码附论文
- 基于树型弱分类器的adaboost演示程序(
- 基于MATLAB的指纹定位算法 NN KNN WK
- 利用KNN对数据进行分类
- AdaBoost等MatLab代码
- GML_AdaBoost_Matlab_Toolbox
- 对训练集测试集采用adaboost算法并比较
- zw_KNN_Matlab.zip
- 手写识别demo
- Matlab机器学习WKNN,加权K近邻,含有数
- K近邻算法、剪辑近邻、压缩近邻等算
- matlab代码KNN,层次聚类,C均值,最邻
- adaboost的matlab实现代码,适合给初学者
- KNN算法的Matlab实现
- KNN,Matlab代码
- matlab-KNN分类器
- KNN算法代码
- SVM+SFS+KNN+SBS+LASSO+SRC算法matlab版
- adaboost 演示demo基于Matlab,学习算法包
- 基于LDA(fisherface)和KNN的人脸识别
- AdaBoost 分类器训练学习
- 神经网络与adaboost的强分类器
- adaboost法人脸检测
- knn matting 国外写的knn-matting
- PNN,smote,BP-AdaBoost等类别不平衡分类
- knn算法matlab实现
- 基于近邻KNN算法的分类器matlab实现
- 超级实用。容易理解的Adaboost的Matla
- 基于adaboost和深度学习网络的人脸表情
评论
共有 条评论