Cluster QuasiRandom Data Using Fuzzy C
Means Clustering
This example shows how FCM clustering works using quasirandom twodimensional data.
Load the data set and plot it.
load fcmdata.dat
plot fcmdata :, ,fcmdata :, ,'o'
Next, invoke the commandline function, fcm, to find two clusters in this data set until the objective function is no longer decreasing much at all.
[center,U,objFcn] = fcm fcmdata, ;
Iteration count = , obj. fcn = . 0 Iteration count = , obj. fcn = . 0 Iteration count = , obj. fcn = . Iteration count = , obj. fcn = . Iteration count = , obj. fcn = . Iteration count = , obj. fcn = . 0 0 Iteration count = , obj. fcn = . 0 Iteration count = , obj. fcn = . Iteration count = , obj. fcn = . 0 Iteration count = 0, obj. fcn = . Iteration count = , obj. fcn = . Iteration count = , obj. fcn = . 0
plot objFcn
title 'Objective Function Values'
xlabel 'Iteration Count'
ylabel 'Objective Function Value'
Finally, plot the two cluster centers found by the fcm function. The large characters in the plot indicate cluster centers.
maxU = max U ;
index = find U ,: == maxU ; index = find U ,: == maxU ; figure
line fcmdata index , , fcmdata index , , 'linestyle',...
'none','marker', 'o','color','g'
line fcmdata index , ,fcmdata index , ,'linestyle',...
'none','marker', 'x','color','r'
hold on
Note: Every time you run this example, the fcm function initializes with different initial conditions. This behavior swaps the order in which the cluster centers are computed and plotted.