Professional Documents
Culture Documents
net/publication/286775150
CITATIONS READS
0 1,536
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Dalia Sami Jasim on 13 December 2015.
Dataset : seeds
Programming language: MATLAB
Results
kama 59 10 1
*******************************************************************
cluster2 correct incorrect class
rosa 65 2 2
*******************************************************************
cluster3 correct incorrect class
Canadian 67 10 3
********************************************************************
clear ; close all; clc
data = load('seed.csv');
class=load('class.csv');
rows=size(data,1);
columns=size(data,2);
%identify clusters
cluster1=[];classify1=[];
cluster2=[];classify2=[];
cluster3=[];classify3=[];
% determine centroids
cent1 = data(58,:);
cent1=cent1(:);
cent2 = data(132,:);
cent2=cent2(:);
cent3 = data(175,:);
cent3=cent3(:);
index1=0;index2=0;index3=0;
n=0;
for k = 1:rows
c = data(k,:);
b=c(:);
cl=class(k,1);
result1=sqrt(sum((cent1-b).^2));
result2=sqrt(sum((cent2-b).^2));
result3=sqrt(sum((cent3-b).^2));
min1=min(result1,result2);
min2=min(min1,result3);
if min2 == result1
index1 = index1 + 1; cluster1(index1,:)=c;classify1(index1,1)=cl;
elseif min2 == result2
index2 = index2 + 1;cluster2(index2,:)=c;classify2(index2,1)=cl;
else
index3 = index3 + 1;cluster3(index3,:)=c;classify3(index3,1)=cl;
end
end
while n <=90
%calculate new centriods
for i=1:columns
cent1(i,1)=sum(cluster1(:,i))/index1;
cent2(i,1)=sum(cluster2(:,i))/index2;
cent3(i,1)=sum(cluster3(:,i))/index3;
end
cluster1=[];cluster2=[];cluster3=[];
n=n+1;
index1=0;index2=0;index3=0;
for k = 1:rows
c = data(k,:);
b=c(:);
result1=sqrt(sum((cent1-b).^2));
result2=sqrt(sum((cent2-b).^2));
result3=sqrt(sum((cent3-b).^2));
min1=min(result1,result2);
min2=min(min1,result3);
if min2 == result1
index1 = index1 + 1; cluster1(index1,:)=c;
elseif min2 == result2
index2 = index2 + 1;cluster2(index2,:)=c;
else
index3 = index3 + 1;cluster3(index3,:)=c;
end
end
end
figure
hold on
scatter(cluster1(:,1),cluster1(:,2),cluster1(:,3),cluster1(:,4),'b','o'
,'LineWidth',5)
scatter(cluster2(:,1),cluster2(:,2),cluster2(:,3),cluster2(:,4),'r','+'
,'LineWidth',5)
scatter(cluster3(:,1),cluster3(:,2),cluster3(:,3),cluster3(:,4),'g','*'
,'LineWidth',5)
scatter(cent1(1,1),cent1(2,1),cent1(3,1),cent1(4,1),'k','+','LineWidth'
,5)
scatter(cent2(1,1),cent2(2,1),cent2(3,1),cent2(4,1),'k','+','LineWidth'
,5)
scatter(cent3(1,1),cent3(2,1),cent3(3,1),cent3(4,1),'k','+','LineWidth'
,5)
legend('cluster1','cluster2','cluster3');
hold off;
max1=max(size(first,1),size(second,1));
max2=max(max1,size(third,1));
if max2==size(first,1)
corr=size(first,1);
incorr=size(second,1)+size(third,1);
cl=first(1,1);
elseif max2==size(second,1)
corr=size(second,1);
incorr=size(first,1)+size(third,1);
cl=second(1,1);
else
corr=size(third,1);
incorr=size(first,1)+size(second,1);
cl=third(1,1);
end
end