fuzzyclust.extensions.PCM#
- class fuzzyclust.extensions.PCM(n_clusters=3, m=2.0, eta=None, eta_scale=1.0, tol=0.0001, max_iter=300, init='fcm', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererPossibilistic c-means clustering (Krishnapuram and Keller).
FCM constrains the memberships of every sample to sum to one over the clusters, so a membership is a relative quantity: an outlier far from all prototypes still receives memberships such as \(1/c\) in every cluster and pulls every prototype toward itself. PCM drops the constraint. The membership \(t_{ik}\) – called typicality – depends only on the distance of the sample to prototype \(i\) relative to a cluster scale \(\eta_i\), not on the distances to the other prototypes. Outliers are atypical of all clusters and no longer distort the prototypes, which makes PCM robust to noise. The price is that the clusters do not interact: PCM is essentially \(c\) independent mode-seeking procedures, and two prototypes may converge to the same dense region (the coincident clusters problem) when the scales \(\eta_i\) are too large or the groups are close. The recommended practice of the original papers, followed here by default, is to initialize PCM with FCM and to estimate \(\eta_i\) from the FCM partition.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Possibilistic exponent \(m>1\). In PCM it controls how fast the typicality decays with the distance (it does not make the partition “fuzzier” as in FCM); the follow-up paper [2] recommends values around 1.5, which give sharper clusters and more robustness than 2.
- eta
None,floator array_likeofshape(n_clusters,), default=None Scale parameters \(\eta_i\) – the squared distance at which the typicality equals 0.5.
Noneestimates them from the initial FCM partition with the factoreta_scale, see Notes.- eta_scale
float, default=1.0 Multiplier \(K\) of the estimated scales (only used when
eta=None). \(K>1\) widens the zone of influence of every cluster and favors coincident clusters, \(K<1\) narrows it.- tol
float, default=1e-4 - max_iter
int, default=300 - init{“fcm”, “random”, “kmeans++”}
orndarray, default=”fcm” "fcm"runsFCM(random start) and uses its partition for \(\eta_i\) and the initial typicalities;"random"/"kmeans++"do the same with the corresponding FCM initialization. An array of shape(n_samples, n_clusters)is used directly as initial (probabilistic) partition, e.g. themembership_of a fitted FCM or GK model.- n_init
int, default=1 Number of restarts (each with its own FCM run); the run with the lowest objective is kept.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) Prototypes \(\mathbf{v}_i\).
- typicality_
ndarrayofshape(n_samples,n_clusters) Typicalities \(t_{ik}\in[0,1]\). Rows do not sum to one.
- membership_
ndarrayofshape(n_samples,n_clusters) The same matrix as
typicality_(PCM has no probabilistic membership); kept so that the generic tools of the toolbox work.- labels_
ndarrayofshape(n_samples,) typicality_.argmax(axis=1).- eta_
ndarrayofshape(n_clusters,) Scales \(\eta_i\) actually used.
- distances_, objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer.
- cluster_centers_
Notes
Compared with the FCM functional \(\sum_i\sum_k\mu_{ik}^m D^2_{ik}\), PCM minimizes
\[J(\mathbf{X};\mathbf{T},\mathbf{V}) = \sum_{i=1}^{c}\sum_{k=1}^{N} t_{ik}^m D^2_{ik} + \sum_{i=1}^{c}\eta_i\sum_{k=1}^{N}(1-t_{ik})^m\]without the constraint \(\sum_i t_{ik}=1\); the second term penalizes the trivial solution \(t_{ik}=0\). The necessary conditions are
\[t_{ik} = \frac{1}{1+\left(D^2_{ik}/\eta_i\right)^{1/(m-1)}},\qquad \mathbf{v}_i = \frac{\sum_k t_{ik}^m\mathbf{x}_k}{\sum_k t_{ik}^m}:\]the prototype update is that of FCM with typicalities in place of memberships, the typicality replaces the FCM membership formula. Since \(J\) is a sum of \(c\) independent terms, the clusters can be found one at a time, and nothing prevents two of them from being identical. The scales are estimated from a probabilistic partition \(\mathbf{U}\) (FCM) as the fuzzy intra-cluster squared distance
\[\eta_i = K\,\frac{\sum_k\mu_{ik}^m D^2_{ik}}{\sum_k\mu_{ik}^m},\qquad K=1 ,\]and kept fixed during the iterations, as recommended in [2]. The original paper [1] also proposes the mean squared distance of the samples whose membership exceeds an \(\alpha\)-cut and, as an optional second phase, re-estimating \(\eta_i\) in this way from the converged typicalities and running PCM a second time; both can be done by passing
etaexplicitly. Because the rows of \(\mathbf{T}\) are not normalized,predict_proba()returns typicalities (as doespredict_typicality()), andlabels_of samples with very small typicality in every cluster should be interpreted with care: comparetypicality_.max(axis=1)against a threshold to find outliers.References
[1]R. Krishnapuram, J. M. Keller, “A possibilistic approach to clustering”, IEEE Trans. Fuzzy Systems 1(2), 98–110, 1993.
Examples
>>> from fuzzyclust.extensions import PCM >>> from fuzzyclust.datasets import make_noisy_blobs >>> X, _ = make_noisy_blobs(random_state=0) >>> pcm = PCM(n_clusters=3, m=1.5, random_state=0).fit(X) >>> pcm.typicality_.shape, pcm.eta_.shape ((330, 3), (3,)) >>> bool(pcm.typicality_.sum(axis=1).max() <= 3.0) True
Examples using fuzzyclust.extensions.PCM#
Possibilistic c-means: typicalities, scales and coincident clusters
Possibilistic fuzzy c-means: memberships and typicalities together