fuzzyclust.cluster.GG#
- class fuzzyclust.cluster.GG(n_clusters=3, m=2.0, gamma=0.0, beta=1000000000000000.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererGath–Geva (GG) fuzzy clustering.
The distance of a sample to a cluster is the inverse of a (scaled) Gaussian density, so clusters are interpreted as Gaussian components with their own covariance and prior probability. GG therefore handles clusters of different shape, size and density, at the price of being more sensitive to initialization than FCM or GK (the exponential distance converges fast to a nearby local optimum). It is usually initialized with FCM or GK.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Fuzziness exponent.
m == 1gives the original fuzzy maximum likelihood estimation (FMLE) algorithm of Bezdek and Dunn;m == 2is recommended because the exponential distance already produces rather crisp partitions.- gamma
float, default=0.0 Covariance regularization weight (shrinkage toward scaled identity), see
GK.- beta
float, default=1e15 Condition-number bound of the covariance matrices.
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”random” Because of the sensitivity to initialization, passing the membership matrix of a fitted FCM/GK model is the recommended practice.
- n_init
int, default=1 Number of random restarts; the run with the lowest final \(J\) is kept (ignored when
initis an array).- 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}\) at convergence (square root of the GG distance).
- covariances_
ndarrayofshape(n_clusters,n_features,n_features) Fuzzy covariance matrices \(\mathbf{F}_{wi}\).
- priors_
ndarrayofshape(n_clusters,) Prior probabilities \(\alpha_i\).
- eigenvalues_, eigenvectors_
Eigen-decomposition of
covariances_(ascending eigenvalues).- objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer.
- cluster_centers_
Notes
The GG distance is
\[D^2_{ik} = \frac{\sqrt{\det\mathbf{F}_{wi}}}{\alpha_i} \exp\!\left(\tfrac12(\mathbf{x}_k-\mathbf{v}_i)^T\mathbf{F}_{wi}^{-1}(\mathbf{x}_k-\mathbf{v}_i)\right),\]with the fuzzy covariance and the prior
\[\mathbf{F}_{wi} = \frac{\sum_k\mu_{ik}^{w}(\mathbf{x}_k-\mathbf{v}_i)(\mathbf{x}_k-\mathbf{v}_i)^T} {\sum_k\mu_{ik}^{w}},\qquad \alpha_i = \frac1N\sum_{k=1}^{N}\mu_{ik},\]where the covariance weighting exponent \(w\) equals
m(w = 2by default, as in the MATLAB toolbox). Memberships and prototypes are updated with the FCM formulas. \(D^2_{ik}\) is the reciprocal of the posterior-weighted Gaussian density, so \(\mu_{ik}\) can be read as the posterior probability of cluster \(i\) given \(\mathbf{x}_k\). All exponentials are evaluated in the log domain for numerical stability.References
[1]I. Gath, A. B. Geva, “Unsupervised optimal fuzzy clustering”, IEEE Trans. Pattern Anal. Mach. Intell. 11(7), 1989.
[2]J. C. Bezdek, J. C. Dunn, “Optimal fuzzy partitions: a heuristic for estimating the parameters in a mixture of normal distributions”, IEEE Trans. Computers, 1975.
Examples
>>> from fuzzyclust.cluster import FCM, GG >>> from fuzzyclust.datasets import make_different_densities >>> X, _ = make_different_densities(random_state=0) >>> fcm = FCM(n_clusters=3, random_state=0).fit(X) >>> gg = GG(n_clusters=3, init=fcm.membership_).fit(X) >>> float(gg.priors_.sum().round(6)) 1.0