Frage

How do you output the data from each cluster using FCM in matlab?

[center,U,obj_fcn] = fcm(data,cluster_n) 
War es hilfreich?

Lösung

I used the U vector to determine which class each datapoint belongs to. It content can be thought of as the probability for each class to belong to a class (notice then all columns sum to 1), so choosing which ever class is most probable is a reasonable approach. This is done by storing the second output argument of max().

Below I have stated some general purpose code you can use.

%# Start parameters and variables
nClasses = 3;
CM = jet(nClasses); %# Colormap for visualization of up to 255 classes

%# Create dataset
data = [mvnrnd([0 0],eye(2),100); mvnrnd([3,3],0.5*eye(2),50)];

%# Cluster
[center,U,obj_fcn] = fcm(data,nClasses); 

%# Extract class assignment
[~,y] = max(U); 

%# Visualize
f1=figure(1);clf
plot(data(:,1),data(:,2),'.k')
hold on
for i = 1 : nClasses
    plot(data(y==i,1),data(y==i,2),'o','color',CM(i,:));
end

enter image description here

EDIT:

To extract the datapoints of one class into a new variable, simply use

class1data = data(y==1,:);

Andere Tipps

My dataset contain 900rows with 4 attribute. Now I oredi cluster it in 9 cluster in each attribute. How I going to code in matlab so that it will show out all data in every cluster? Now I am only get center,U, obj_func only.

THE data I get is for me to calculate the standard deviation. So i need all the in every cluster.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top