# decomposition.rar

• wwwxxxrrr
了解作者
• C/C++
开发工具
• 2KB
文件大小
• rar
文件格式
• 0
收藏次数
• 1 积分
下载积分
• 1
下载次数
• 2020-06-13 19:09
上传日期

decomposition.rar
• IRIS.mat
1KB
• decomposition.m
2.4KB
• IRIS.csv
2.4KB

% 初始化并载入数据 clear all; close all; load('IRIS.mat'); % 第一次分解聚类，分离出第一类花种 e=[]; N=150; for i=1:150 G1=IRIS; G2=[]; N1=size(G1,1); ex1=mean(G1,1); ex1=ex1+(ex1-G1(i,:))/(N1-1); ex2=G1(i,:); G2(1,:)=G1(i,:); G1(i,:)=[]; N1=size(G1,1); N2=size(G2,1); E=N1*N2/N*(ex1-ex2)*(ex1-ex2)'; e(i)=E; end [m,index]=max(e); G1=IRIS; G2=[]; G2(1,:)=G1(index,:); G1(index,:)=[]; GG1=G1; GG2=G2; EE(1)=m; for j=2:150 e=[]; for i=1:151-j G1=GG1; G2=GG2; N1=size(G1,1); N2=size(G2,1); ex1=mean(G1,1); ex2=mean(G2,1); ex1=ex1+(ex1-G1(i,:))/(N1-1); ex2=ex2-(ex2-G1(i,:))/(N2+1); G2(j,:)=G1(i,:); G1(i,:)=[]; N1=size(G1,1); N2=size(G2,1); E=N1*N2/N*(ex1-ex2)*(ex1-ex2)'; e(i)=E; end [m,index]=max(e); G1=GG1; G2=GG2; G2(j,:)=G1(index,:); G1(index,:)=[]; GG1=G1; GG2=G2; EE(j)=m; if(EE(j)<EE(j-1)) break; end end G1(N1+1,:)=G2(N2,:); G2(N2,:)=[]; N1=size(G1,1); N2=size(G2,1); GG1=G1; GG2=G2; % 第二次分解聚类，分离出第二类花种和第三类花种 EE=[]; e=[]; N=97; for i=1:97 G2=GG2; G3=[]; N2=size(G2,1); ex2=mean(G2,1); ex2=ex2+(ex2-G2(i,:))/(N2-1); ex3=G2(i,:); G3(1,:)=G2(i,:); G2(i,:)=[]; N2=size(G2,1); N3=size(G3,1); E=N2*N3/N*(ex2-ex3)*(ex2-ex3)'; e(i)=E; end [m,index]=max(e); G2=GG2; G3=[]; G3(1,:)=G2(index,:); G2(index,:)=[]; GG2=G2; GG3=G3; EE(1)=m; for j=2:97 e=[]; for i=1:98-j G2=GG2; G3=GG3; N2=size(G2,1); N3=size(G3,1); ex2=mean(G2,1); ex3=mean(G3,1); ex2=ex2+(ex2-G2(i,:))/(N2-1); ex3=ex3-(ex3-G2(i,:))/(N3+1); G3(j,:)=G2(i,:); G2(i,:)=[]; N2=size(G2,1); N3=size(G3,1); E=N2*N3/N*(ex2-ex3)*(ex2-ex3)'; e(i)=E; end [m,index]=max(e); G2=GG2; G3=GG3; G3(j,:)=G2(index,:); G2(index,:)=[]; GG2=G2; GG3=G3; EE(j)=m; if(EE(j)<EE(j-1)) break; end end G2(N2+1,:)=G3(N3,:); G3(N3,:)=[]; % 显示结果 plot(G1(:,3),G1(:,4),'r*',G2(:,3),G2(:,4),'b*',G3(:,3),G3(:,4),'g*'); legend('第一类','第二类','第三类'); xlabel('IRIS 第三维数据'); ylabel('IRIS 第四维数据'); title('分类结果示意图');

相关推荐