Using matlab FCM to cluster my own data

1.5k Views Asked by At

I am trying to use fcm (fuzzy C-means clustering) matlab tool, but I don't know how to put my own data. I am trying to cluster nodes based on distance from the center. So my data are x and y coordinates. I am basically trying to compare it with k-means this is how I did the k-means:

X=[x_users,y_users];
nc=20;             
idx = kmeans(X,nc);

I need to know how to do the same thing with fcm, am sorry if my question is too naive.

Thanks,

1

There are 1 best solutions below

2
On BEST ANSWER
fcm(X,nc); 

will do it. For example:

data = rand(100,2);
nc = 2;
[center,U,obj_fcn] = fcm(data,nc);
plot(data(:,1),data(:,2),'o');
maxU = max(U);
index1 = find(U(1,:)== maxU);
index2 = find(U(2,:)== maxU);
line(data(index1,1),data(index1,2),'linestyle','none',...
     'marker','*','color','g');
line(data(index2,1),data(index2,2),'linestyle','none',...
     'marker', '*','color','r');

enter image description here

Using kmeans the answer would be like the following plot:

idx = kmeans(data,nc);
data1 = data(idx==1,:);
data2 = data(idx==2,:);
figure;plot(data1(:,1),data1(:,2),'x');
hold on;plot(data2(:,1),data2(:,2),'or');

enter image description here