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:
BaseFuzzyClustererGustafson–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_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Fuzziness exponent \(m>1\).
- rho
floator array_likeofshape(n_clusters,), default=None Cluster volumes \(\rho_i\) (
Nonemeans all equal to one).- gamma
float, 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).
- beta
float, default=1e15 Upper bound on the condition number of \(\mathbf{F}_i\) (eigenvalues below \(\lambda_{\max}/\beta\) are raised).
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”random” - n_init
int, default=1 Number of random restarts; the run with the lowest final \(J\) is kept.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) - membership_
ndarrayofshape(n_samples,n_clusters) - labels_
ndarrayofshape(n_samples,) - distances_
ndarrayofshape(n_samples,n_clusters) \(D_{ik\mathbf{A}_i}\) at convergence.
- covariances_
ndarrayofshape(n_clusters,n_features,n_features) Fuzzy covariance matrices \(\mathbf{F}_i\) (after regularization).
- norm_matrices_
ndarrayofshape(n_clusters,n_features,n_features) Norm-inducing matrices \(\mathbf{A}_i\).
- eigenvalues_
ndarrayofshape(n_clusters,n_features) Eigenvalues of \(\mathbf{F}_i\) in ascending order (cluster shape).
- eigenvectors_
ndarrayofshape(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.
- cluster_centers_
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
gammaandbeta) 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)