码迷,mamicode.com
首页 > 其他好文 > 详细

LDA

时间:2017-05-13 17:02:47      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:plot   clear   end   for   ros   lda   sqrt   sum   hold   

clc;close all;clear all
c1=[2 2 2;
1 2 3];
c2=[4 5 6;
3 3 4];
c=[c1 c2];
plot(c1(1,:),c1(2,:),‘*‘,c2(1,:),c2(2,:),‘*‘);axis([0 8 0 8]);hold on
u=mean(c,2);
u1=mean(c1,2);
u2=mean(c2,2);

s1=zeros(2,2);
s2=zeros(2,2);
for i=1:3
s1=s1+(c1(:,i)-u1)*(c1(:,i)-u1)‘;
s2=s2+(c2(:,i)-u2)*(c2(:,i)-u2)‘;
end
SB=s1+s2;
w=inv(SB)*(u1-u2);
w=w/sqrt(sum(w‘*w));

v=[w(2);-w(1)];
b=-v‘*u;
x1=0:10;
x2=(-b-v(1)*x1)/v(2);
plot(x1,x2);hold on
c=c-[u u u u u u];
p=w‘*c;
x=w*p;
x=x+[u u u u u u]
plot(x(1,:),x(2,:),‘o‘)

LDA

标签:plot   clear   end   for   ros   lda   sqrt   sum   hold   

原文地址:http://www.cnblogs.com/xlqtlhx/p/6849263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!