fuzzyclust.cluster.GK#

class fuzzyclust.cluster.GK(n_clusters=3, m=2.0, rho=None, gamma=0.0, beta=1000000000000000.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Gustafson–Kessel (GK) fuzzy clustering.

Each cluster has its own norm-inducing matrix \(\mathbf{A}_i\) derived from the fuzzy covariance matrix of the cluster, so clusters of different orientation and elongation (ellipsoids) can be detected within one data set. The volume of each cluster is fixed by \(\rho_i\).

Parameters:
n_clustersint, default=3

Number of clusters \(c\).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

rhofloat or array_like of shape (n_clusters,), default=None

Cluster volumes \(\rho_i\) (None means all equal to one).

gammafloat, default=0.0

Covariance regularization weight \(\gamma\in[0,1]\): shrinks every \(\mathbf{F}_i\) toward a scaled identity. Recommended for small or nearly collinear clusters (Babuška, van der Veen & Kaymak, 2002).

betafloat, default=1e15

Upper bound on the condition number of \(\mathbf{F}_i\) (eigenvalues below \(\lambda_{\max}/\beta\) are raised).

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)
membership_ndarray of shape (n_samples, n_clusters)
labels_ndarray of shape (n_samples,)
distances_ndarray of shape (n_samples, n_clusters)

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

covariances_ndarray of shape (n_clusters, n_features, n_features)

Fuzzy covariance matrices \(\mathbf{F}_i\) (after regularization).

norm_matrices_ndarray of shape (n_clusters, n_features, n_features)

Norm-inducing matrices \(\mathbf{A}_i\).

eigenvalues_ndarray of shape (n_clusters, n_features)

Eigenvalues of \(\mathbf{F}_i\) in ascending order (cluster shape).

eigenvectors_ndarray of shape (n_clusters, n_features, n_features)

Corresponding eigenvectors (columns); the first column is the normal direction of the “flattest” extent of the cluster, useful for extracting local linear models.

objective_, objective_history_, n_iter_

See BaseFuzzyClusterer.

Notes

GK minimizes

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

subject to the volume constraint \(\det\mathbf{A}_i=\rho_i\), which gives

\[\mathbf{A}_i = \left[\rho_i\det(\mathbf{F}_i)\right]^{1/n}\mathbf{F}_i^{-1},\qquad \mathbf{F}_i = \frac{\sum_k\mu_{ik}^m(\mathbf{x}_k-\mathbf{v}_i)(\mathbf{x}_k-\mathbf{v}_i)^T} {\sum_k\mu_{ik}^m}.\]

The membership and prototype updates are those of FCM. The numerically robust variant (regularization by gamma and beta) follows [2].

References

[1]

D. E. Gustafson, W. C. Kessel, “Fuzzy clustering with a fuzzy covariance matrix”, Proc. IEEE CDC, 1979.

[2]

R. Babuška, P. J. van der Veen, U. Kaymak, “Improved covariance estimation for Gustafson–Kessel clustering”, Proc. FUZZ-IEEE, 2002.

Examples

>>> from fuzzyclust.cluster import GK
>>> from fuzzyclust.datasets import make_ellipses
>>> X, _ = make_ellipses(random_state=0)
>>> gk = GK(n_clusters=3, random_state=0).fit(X)
>>> gk.covariances_.shape
(3, 2, 2)