how draw line between two classes.
Show older comments
I have Linear classification, but I don't know how to draw the projected line into my data. The line should look like the picture in page 21 from attached pdf, but instead it is been projected in opposite. The problem is in quiver. Is there a way to project the line as the documentation? Thank you in advance.
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;
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);
figure;
y1 = x1'*w;
y2 = x2'*w;
hist([y1 y2])
Answers (0)
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!