【发布时间】:2016-07-06 08:42:28
【问题描述】:
我有两个问题。 我有用于线性判别分析的附加代码,它处理两个类 - 每两个特征。这是非常基本的。 然而,
我不知道为什么我的投影线和教程不一样。请告诉我我对附件 pdf 所做的错误实现在哪里。
http://research.cs.tamu.edu/prism/lectures/pr/pr_l10.pdf http://www.di.univr.it/documenti/OccorrenzaIns/matdid/matdid437773.pdf
% Fisher's linear discriminant.
% : xi is column vector of which element is test metric.
% Therefore size of row is the number of test metrics.
% Number of column is the number of data sets.
% x1 = rand(2, 30) + 0.75.*ones(2,30); %[d1(:,c1) d1(:,c2)]';
% x2 = rand(2, 30) + 0.3 .*ones(2,30); %[d2(:,c1) d2(:,c2)]';
x1=[1 2;2 3;3 3;4 5;5 5]' % the first class 5 observations
x2=[1 0;2 1;3 1;3 2;5 3]' % the second class 6 observations
m1 = mean(x1')';
m2 = mean(x2')';
m = m1 + m2;
Sw1 = zeros(size(x1, 1), size(x1,1));
Sw2 = zeros(size(x1, 1), size(x1,1));
for i = 1:size(x1,1)
Sw1 = Sw1 + (x1(:,i)-m1)*(x1(:,i)-m1)';
end
for i = 1:size(x2,1)
Sw2 = Sw2 + (x2(:,i)-m2)*(x2(:,i)-m2)';
end
Sw = Sw1 + Sw2;
w = Sw^(-1)*(m2-m1);
scatter(x1(1,:), x1(2,:), 10, 'ro');
hold on;
scatter(x2(1,:), x2(2,:),10,'bo');
c = 0.5.*m; %Average mean.ie. m/2
quiver(c(1,1), c(2,1), 1, -w(1,1)/w(2,1));
quiver(c(1,1), c(2,1), -1, w(1,1)/w(2,1));
quiver(w(1,1),w(2,1), 0.5)
hold off;
figure;
y1 = x1'*w;
y2 = x2'*w;
hist([y1 y2])
newy=w'*newp;
%newp is new point
diff1=abs(m1-newy);
diff2=abs(m2-newy);
if diff1 >=diff2
%newp is included in class1
else
%newp is included in class2
It has to be something similar to the following picture
[![smthg simialr to the following final results][3]][3]
【问题讨论】:
标签: algorithm matlab machine-learning linear-algebra linear-regression