Main Content

Cluster Quasi-Random Data Using Fuzzy C-Means Clustering

This example shows how FCM clustering works using quasi-random two-dimensional data.

Load the data set and plot it.

load fcmdata.dat

Figure contains an axes. The axes contains an object of type line.

Next, invoke the command-line 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,2);
Iteration count = 1, obj. fcn = 8.970479
Iteration count = 2, obj. fcn = 7.197402
Iteration count = 3, obj. fcn = 6.325579
Iteration count = 4, obj. fcn = 4.586142
Iteration count = 5, obj. fcn = 3.893114
Iteration count = 6, obj. fcn = 3.810804
Iteration count = 7, obj. fcn = 3.799801
Iteration count = 8, obj. fcn = 3.797862
Iteration count = 9, obj. fcn = 3.797508
Iteration count = 10, obj. fcn = 3.797444
Iteration count = 11, obj. fcn = 3.797432
Iteration count = 12, obj. fcn = 3.797430

center contains the coordinates of the two cluster centers, U contains the membership grades for each of the data points, and objFcn contains a history of the objective function across the iterations.

The fcm function is an iteration loop built on top of the following routines:

  • initfcm - initializes the problem

  • distfcm - performs Euclidean distance calculation

  • stepfcm - performs one iteration of clustering

To view the progress of the clustering, plot the objective function.

title('Objective Function Values')   
xlabel('Iteration Count')
ylabel('Objective Function Value')

Figure contains an axes. The axes with title Objective Function Values contains an object of type line.

Finally, plot the two cluster centers found by the fcm function. The large characters in the plot indicate cluster centers.

maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2,:) == maxU);
line(fcmdata(index1,1), fcmdata(index1,2), 'linestyle',...
                        'none','marker', 'o','color','g')
                        'none','marker', 'x','color','r')
hold on

Figure contains an axes. The axes contains 4 objects of type line.

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.

See Also

Related Topics