Fuzzy c means clustering MATLAB fcm

fcm
Fuzzy c­means clustering

collapse all in page

Syntax
[centers,U] = fcm data,Nc

example

[centers,U] = fcm data,Nc,options

example

[centers,U,objFunc] = fcm

example

___

Description

[centers,U] = fcm data,Nc  performs fuzzy c­means clustering on the
given data and returns Nc cluster centers.

example

[centers,U] = fcm data,Nc,options  specifies additional clustering
options.

example

[centers,U,objFunc] = fcm

example

___

 also returns the objective function values

at each optimization iteration for all of the previous syntaxes.


Examples

collapse all

Cluster Data Using Fuzzy C­Means Clustering
Load data.
load fcmdata.dat

Find   clusters using fuzzy c­means clustering.
[centers,U] = fcm fcmdata,

Iteration count = 
Iteration count = 
Iteration count = 
Iteration count = 
Iteration count = 
Iteration count = 
Iteration count = 
Iteration count = 
Iteration count = 

Iteration count = 
Iteration count = 
Iteration count = 

;

, obj. fcn =  . 0
, obj. fcn =  .
0
, obj. fcn =  .
, obj. fcn =  .
, obj. fcn =  .
, obj. fcn =  . 0 0
, obj. fcn =  .
0
, obj. fcn =  .
, obj. fcn =  .
0
0, obj. fcn =  .
, obj. fcn =  .

, obj. fcn =  .
0

Classify each data point into the cluster with the largest membership value.
maxU = max U ;
index  = find U
index  = find U

,:  == maxU ;
,:  == maxU ;

Plot the clustered data and cluster centers.
plot fcmdata index , ,fcmdata index , ,'ob'
hold on
plot fcmdata index , ,fcmdata index , ,'or'
plot centers , ,centers , ,'xb','MarkerSize',
plot centers , ,centers , ,'xr','MarkerSize',
hold off

,'LineWidth',

,'LineWidth',

Specify Fuzzy Overlap Between Clusters
Create a random data set.
data = rand

00,

;

Specify a large fuzzy partition matrix exponent to increase the amount of fuzzy ovrelap between the clusters.
options = [ .0 NaN NaN 0];

Cluster the data.
[centers,U] = fcm data, ,options ;

Configure Clustering Termination Conditions
Load the clustering data.
load clusterdemo.dat


Set the clustering termination conditions such that the optimization stops when either of the following occurs:
The number of iterations reaches a maximum of 

.

The objective function improves by less than 0.00  between two consecutive iterations.
options = [NaN 

 0.00  0];

The first option is NaN, which sets the fuzzy partition matrix exponent to its default value of . Setting the fourth option
to 0 suppresses the objective function display.
Cluster the data.
[centers,U,objFun] = fcm clusterdemo, ,options ;

View the objective function vector to determine which termination condition stopped the clustering.

objFun

objFun =

    .
    .
    .
    .
    .0
    .
    .
    . 0
    0.
    .
    .
    . 0
    . 0

The optimization stopped because the objective function improved by less than 0.00 between the final two iterations.

Related Examples
Cluster Quasi­Random Data Using Fuzzy C­Means Clustering
Adjust Fuzzy Overlap in Fuzzy C­Means Clustering


Input Arguments

collapse all

data — Data set to be clustered
matrix
Data set to be clustered, specified as a matrix with Nd rows, where Nd is the number of data points. The number of
columns in data is equal to the data dimensionality.

Nc — Number of clusters
integer
Number of clusters, specified as an integer greater than  .

options — Clustering options
vector
Clustering options, specified as a vector with the following elements:
Option

Description


options

Exponent for the fuzzy partition matrix U, specified as a scalar
greater than  .0. This option controls the amount of fuzzy
overlap between clusters, with larger values indicating a
greater degree of overlap.

Default

.0

If your data set is wide with a lot of overlap between potential
clusters, then the calculated cluster centers might be very
close to each other. In this case, each data point has
approximately the same degree of membership in all
clusters. To improve your clustering results, decrease this
value, which limits the amount of fuzzy overlap during
clustering.
For an example of fuzzy overlap adjustment, see Adjust
Fuzzy Overlap in Fuzzy C­Means Clustering.

options

Maximum number of iterations, specified as a positive
integer.

00

options

Minimum improvement in objective function between two
consecutive iterations, specified as a positive scalar.

e‐

options

Information display toggle indicating whether to display the
objective function value after each iteration, specified as one

of the following:

0 — Do not display objective function.
 — Display objective function.

If any element of options is NaN, the default value for that option is used.
The clustering process stops when the maximum number of iterations is reached or when the objective function
improvement between two consecutive iterations is less than the specified minimum.

Output Arguments

collapse all

centers — Cluster centers
matrix
Final cluster centers, returned as a matrix with Nc rows containing the coordinates of each cluster center. The number of
columns in centers is equal to the dimensionality of the data being clustered.

U — Fuzzy partition matrix
matrix
Fuzzy partition matrix, returned as a matrix with Nc rows and Nd columns. Element U i,j indicates the degree of
membership of the jth data point in the ith cluster. For a given data point, the sum of the membership values for all clusters
is one.

objFunc — Objective function values
vector
Objective function values for each iteration, returned as a vector.

More About

expand all

Algorithms
Fuzzy c­means (FCM) is a clustering method that allows each data point to belong to multiple clusters with varying
degrees of membership.
FCM is based on the minimization of the following objective function
D

N

2

฀xi − cj฀ ,
Jm = ฀ ฀ μm
ij
i =1 j=1

where
D is the number of data points.
N is the number of clusters.
m is fuzzy partition matrix exponent for controlling the degree of fuzzy overlap, with m > 1. Fuzzy overlap refers to how
fuzzy the boundaries between clusters are, that is the number of data points that have significant membership in more
than one cluster.
xi is the ith data point.
cj is the center of the jth cluster.
μ ij is the degree of membership of xi in the jth cluster. For a given data point, xi, the sum of the membership values for
all clusters is one.
fcm performs the following steps during clustering:
1.  Randomly initialize the cluster membership values, μ ij.
2.  Calculate the cluster centers:
D

cj =



i =1
D



μm x
ij i

i =1

.

μm
ij

3.  Update μ ij according to the following:
1

μij =

1

N



k =1

฀฀x −c ฀ ฀m2−1
i j

.

฀฀x −c ฀ ฀
i k

4.  Calculate the objective function, Jm.
5.  Repeat steps 2–4 until Jm improves by less than a specified minimum threshold or until after a specified maximum
number of iterations.
Fuzzy Clustering

References
[1] Bezdec, J.C., Pattern Recognition with Fuzzy Objective Function Algorithms, Plenum Press, New York, 1981.

See Also
findcluster | genfis

Introduced before R2006a