fuzzyclust.cluster.FCM#

class fuzzyclust.cluster.FCM(n_clusters=3, m=2.0, norm='euclidean', tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Fuzzy c-means clustering (Dunn, Bezdek).

Every sample belongs to every cluster with a membership degree \(\mu_{ik}\in[0,1]\), \(\sum_i\mu_{ik}=1\). Prototypes are membership-weighted means and the distance is a fixed inner-product norm, so FCM detects (hyper)spherical clusters of roughly equal size.

Parameters:
n_clustersint, default=3

Number of clusters \(c\).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

norm{“euclidean”, “diagonal”, “mahalanobis”} or ndarray, default=”euclidean”

Norm-inducing matrix \(\mathbf{A}\) shared by all clusters (an explicit matrix has shape (n_features, n_features)): identity, the inverse diagonal variances of the data, the inverse of the data covariance (Mahalanobis norm), or an explicit matrix.

tolfloat, default=1e-4
max_iterint, default=300
init{“random”, “kmeans++”} or ndarray, default=”random”
n_initint, default=1

Number of random restarts; the run with the lowest final \(J\) is kept.

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
cluster_centers_ndarray of shape (n_clusters, n_features)

Prototypes \(\mathbf{v}_i\).

membership_ndarray of shape (n_samples, n_clusters)

Fuzzy partition \(\mathbf{U}^T\).

labels_ndarray of shape (n_samples,)
distances_ndarray of shape (n_samples, n_clusters)

\(D_{ik\mathbf{A}}\) at convergence.

norm_matrix_ndarray of shape (n_features, n_features)

The norm-inducing matrix \(\mathbf{A}\) actually used.

covariances_ndarray of shape (n_clusters, n_features, n_features)

Fuzzy covariance matrices \(\mathbf{F}_i\) of the final partition (not used by the algorithm, provided for analysis and plotting).

objective_, objective_history_, n_iter_

See BaseFuzzyClusterer.

Notes

FCM minimizes the c-means functional

\[J(\mathbf{X};\mathbf{U},\mathbf{V}) = \sum_{i=1}^{c}\sum_{k=1}^{N} \mu_{ik}^m\, D^2_{ik\mathbf{A}}, \qquad D^2_{ik\mathbf{A}} = (\mathbf{x}_k-\mathbf{v}_i)^T\mathbf{A}(\mathbf{x}_k-\mathbf{v}_i)\]

by Picard iteration through the necessary conditions

\[\mu_{ik} = \frac{1}{\sum_{j=1}^{c}\left(D_{ik\mathbf{A}}/D_{jk\mathbf{A}}\right)^{2/(m-1)}}, \qquad \mathbf{v}_i = \frac{\sum_{k=1}^{N}\mu_{ik}^m\mathbf{x}_k}{\sum_{k=1}^{N}\mu_{ik}^m}.\]

References

[1]

J. C. Dunn, “A fuzzy relative of the ISODATA process and its use in detecting compact well-separated clusters”, J. Cybernetics 3, 1973.

[2]

J. C. Bezdek, “Pattern Recognition with Fuzzy Objective Function Algorithms”, Plenum Press, 1981.

Examples

>>> from fuzzyclust.cluster import FCM
>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> X, _ = make_fuzzy_blobs(random_state=0)
>>> fcm = FCM(n_clusters=3, m=2.0, random_state=0).fit(X)
>>> float(fcm.membership_.sum(axis=1).round(6).min())
1.0