资源描述:
《fisher线性识别与最邻近判别法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Fisher法:Wdbc:sample1=data(23:46,:);sample2=data(538:562,:);sample=[sample1sample2];sp=data1(1:569,:);sample_m1=mean(sample1);sample_m2=mean(sample2);m1=sample_m1';m2=sample_m2';sb=(m1-m2)*(m1-m2)';s1=zeros(30);forn=1:19temp=(sample1(n,:)'-m1)*(sample1(n,:)'-m1)';s1=s1+temp;end;s2=zero
2、s(30);forn=1:24temp=(sample2(n,:)'-m2)*(sample2(n,:)'-m2)';s2=s2+temp;end;sw=s1+s2;vw=(sw)(m1-m2);a_m1=vw'*m1;a_m2=vw'*m2;w0=(a_m1+a_m2)/2;forn=1:569if(vw'*data(n,:)'-w0>0)m1(n,:)=77;elsem1(n,:)=66;end;end;count1=0;count2=0;forn=1:569ifm1(n,:)==sp(n,:)&&m1(n,:)==77count1=count1+1;end
3、ifm1(n,:)==sp(n,:)&&m1(n,:)==66count2=count2+1;endendclass1_rate=count1/212class2_rate=count2/357class1_rate=0.8113class2_rate=0.7731sample1=data(1:14,:);sample2=data(99:117,:);sample=[sample1sample2];sp=data1(1:208,:);sample_m1=mean(sample1);sample_m2=mean(sample2);m1=sample_m1';m2=s
4、ample_m2';sb=(m1-m2)*(m1-m2)';s1=zeros(60);forn=1:13temp=(sample1(n,:)'-m1)*(sample1(n,:)'-m1)';s1=s1+temp;end;s2=zeros(60);forn=1:18temp=(sample2(n,:)'-m2)*(sample2(n,:)'-m2)';s2=s2+temp;end;sw=s1+s2;vw=(sw)(m1-m2);a_m1=vw'*m1;a_m2=vw'*m2;w0=(a_m1+a_m2)/2;forn=1:208if(vw'*data(n,:)'
5、-w0>0)m1(n,:)=1;elsem1(n,:)=2;end;end;count1=0;count2=0;forn=1:208ifm1(n,:)==sp(n,:)&&m1(n,:)==1count1=count1+1;endifm1(n,:)==sp(n,:)&&m1(n,:)==2count2=count2+1;endendclass1_rate=count1/98class2_rate=count2/110class1_rate=0.5816class2_rate=0.7545最邻近法:clcsample1=data(23:46,:);sample2=d
6、ata(538:562,:);sample=[sample1sample2];test=datalth=zeros(569,49);forn=1:569fori=1:49lth(n,i)=((test(n,1)-sample(i,1))^2+(test(n,2)-sample(i,2))^2+(test(n,3)-sample(i,3))^2+(test(n,4)-sample(i,4))^2+(test(n,5)-sample(i,5))^2+(test(n,6)-sample(i,6))^2+(test(n,7)-sample(i,7))^2+(test(n,
7、8)-sample(i,8))^2+(test(n,9)-sample(i,9))^2+(test(n,10)-sample(i,10))^2+(test(n,11)-sample(i,11))^2+(test(n,12)-sample(i,12))^2+(test(n,13)-sample(i,13))^2+(test(n,14)-sample(i,14))^2+(test(n,15)-sample(i,15))^2+(test(n,16)-sample(i,16))^2+(test(n,17)-sample(i,17))^2+(test(n,18)-sampl
8、e(i,1