【adaboost分类】基于adaboost实现一维数据分类附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信       无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机 

⛄ 内容介绍

分类是数据挖掘研究范畴中为了解决分类问题而提出的方法,同时它也是一种重要的分析数据的技术.作为一种有效的科学研究工具,组合分类器在医疗诊断,手写体识别,人脸识别,推荐系统等领域有着广泛的应用.

⛄ 部分代码

% Example for adaboost.m

%

% Type "edit adaboost.m" to see the code

% Make training data of two classes "red" and "blue"

 % with 2 features for each sample (the position  x and y).

  angle=rand(200,1)*2*pi; l=rand(200,1)*40+30; blue=[sin(angle).*l cos(angle).*l];

  angle=rand(200,1)*2*pi; l=rand(200,1)*40;    red=[sin(angle).*l cos(angle).*l];

 % All the training data

  datafeatures=[blue;red];

  dataclass(1:200)=-1; dataclass(201:400)=1;

 % Show the data

  figure, subplot(2,2,1), hold on; axis equal;

  plot(blue(:,1),blue(:,2),'b.'); plot(red(:,1),red(:,2),'r.');

  title('Training Data');

  

 % Use Adaboost to make a classifier

  [classestimate,model]=adaboost('train',datafeatures,dataclass,50);

 % Training results

 % Show results

  blue=datafeatures(classestimate==-1,:); red=datafeatures(classestimate==1,:);

  I=zeros(161,161);

  for i=1:length(model)

      if(model(i).dimension==1)

          if(model(i).direction==1), rec=[-80 -80 80+model(i).threshold 160];

          else rec=[model(i).threshold -80 80-model(i).threshold 160 ];

          end

      else

          if(model(i).direction==1), rec=[-80 -80 160 80+model(i).threshold];

          else rec=[-80 model(i).threshold 160 80-model(i).threshold];

          end

      end

      rec=round(rec);

      y=rec(1)+81:rec(1)+81+rec(3); x=rec(2)+81:rec(2)+81+rec(4);

      I=I-model(i).alpha; I(x,y)=I(x,y)+2*model(i).alpha;    

  end

 subplot(2,2,2), imshow(I,[]); colorbar; axis xy;

 colormap('jet'), hold on

 plot(blue(:,1)+81,blue(:,2)+81,'bo');

 plot(red(:,1)+81,red(:,2)+81,'ro');

 title('Training Data classified with adaboost model');

 % Show the error verus number of weak classifiers

 error=zeros(1,length(model)); for i=1:length(model), error(i)=model(i).error; end 

 subplot(2,2,3), plot(error); title('Classification error versus number of weak classifiers');

 % Make some test data

  angle=rand(200,1)*2*pi; l=rand(200,1)*70; testdata=[sin(angle).*l cos(angle).*l];

 % Classify the testdata with the trained model

  testclass=adaboost('apply',testdata,model);

 % Show result

  blue=testdata(testclass==-1,:); red=testdata(testclass==1,:);

 % Show the data

  subplot(2,2,4), hold on

  plot(blue(:,1),blue(:,2),'b*');

  plot(red(:,1),red(:,2),'r*');

  axis equal;

  title('Test Data classified with adaboost model');

⛄ 运行结果

⛄ 参考文献

[1] 董庆伟. 基于Adaboost算法的不平衡数据集分类效果研究[J]. 长春师范大学学报, 2022, 41(6):4.

[2] 黄道, 何晋, 刘志愿,等. 分类算法adaboostM1和multiboostAB对草药数据分类的比较[J]. 中国新通信, 2014, 16(6):1.

[3] 胡燕祝, 王松. 一种基于AdaBoost算法的感知器网络数据分类方法:, CN109726767A[P]. 2019.

⛳️ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值