kawtherhamad99
unread,Dec 1, 2014, 9:56:54 PM12/1/14You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Can you please help me how to find the decision boundary between 4 clusters in matlab. I have the below code, i want to find the decsion boundaries, i want to find then the bet error rate. Can i consider the data as training data? if yes, how can i then implement the test data?
clear all
clc
load fisheriris
labels = (1:1200);
T=[ 2+2*i 2-2*i -2+2*i -2-2*i];
A=randn(150,2)+2*ones(150,2); C=randn(150,2)-2*ones(150,2);
B=randn(150,2)+2*ones(150,2); F=randn(150,2)-2*ones(150,2);
D=randn(150,2)+2*ones(150,2); G=randn(150,2)-2*ones(150,2);
E=randn(150,2)+2*ones(150,2); H=randn(150,2)-2*ones(150,2);
X = [A; B; D; C; F; E; G; H];
[idx, centroids] = kmeans(X, 4, 'Replicates', 20);
x = X(:,1);
y = X(:,2);
classifierType = 'quadratic'; %# 'quadratic', 'linear'
npoints=100;
mn = min(X); mx = max(X);
[I,J] = meshgrid( linspace(mn(1),mx(1),npoints), linspace(mn(2),mx(2),npoints));
[K,L] = meshgrid( linspace(mn(1),mx(1),npoints), linspace(mn(2),mx(2),npoints));
I = I(:); J = J(:); K = K(:); L = L(:);
[C,err,P,logp,coeff] = classify([I J K L], X, labels, classifierType);
figure;
hold on;
colors = 'rgbk';
for num = 1 : 4
plot(x(idx == num), y(idx == num), [colors(num) '.']);
end
plot(centroids(:,1), centroids(:,2), 'c.', 'MarkerSize', 14);
NUM_K=4;
%# draw decision boundaries between pairs of clusters
for i=1:NUM_K
for j=i+1:NUM_K
if strcmp(coeff(i,j).type, 'quadratic')
K = coeff(i,j).const;
L = coeff(i,j).linear;
Q = coeff(i,j).quadratic;
f = sprintf('0 = %g + %g*x + %g*y + %g*x^2 + %g*x.*y + %g*y.^2',...
K,L,Q(1,1),Q(1,2)+Q(2,1),Q(2,2));
else
K = coeff(i,j).const;
L = coeff(i,j).linear;
f = sprintf('0 = %g + %g*x + %g*y', K,L(1),L(2));
end
h2 = ezplot(f, [mn(1) mx(1) mn(2) mx(2)]);
set(h2, 'Color','k', 'LineWidth',2)
end
end
grid;
Thank you.
Kawther