Chapter 6
Robust and shape-oriented variants of fuzzy c-means
Fuzzy c-means rests on three assumptions: the memberships of every sample sum to one, every cluster is a point in the data space, and the distance to that point is Euclidean. This chapter relaxes them one at a time, each time by a small change to the FCM template of chapter 3—a different membership formula, distance, or prototype update—and all methods live in fuzzyclust.extensions with the common interface of the toolbox. Possibilistic c-means, possibilistic fuzzy c-means, and noise clustering drop or loosen the sum-to-one constraint, so that outliers are recognized instead of being shared out among the clusters. Kernel fuzzy c-means measures the distance in the feature space of a kernel, where rings and moons become spheres; fuzzy c-varieties and c-shells replace the point by a line or a circle; volume prototypes replace it by a core of zero distance, which removes the bias toward clusters of equal size and, with adaptive merging, finds the number of clusters during the iteration; and feature weights learned with the partition adapt the distance to the features that matter. The graph-based methods of the next chapter take the opposite route and abandon the prototype altogether.
6.1 Problem and idea
Two things can go wrong when fuzzy c-means meets real data. The first is the partition. The constraint makes every membership a relative quantity: it says to which prototype a sample is closer, not whether it is close to any of them. A sample far from all prototypes still shares a total membership of one among them and, since the prototype update (3.7) weighs every sample by , such an outlier pulls the prototypes toward itself. The second is the prototype. A point prototype with a fixed norm describes spherical clusters (section 3.2.3), one with an adaptive norm ellipsoidal clusters (sections 3.2.4 and 3.2.5); a group of points along a line, a ring, or a curved arc has no useful center, and the algorithm tiles it into spherical or ellipsoidal pieces.
The methods of this chapter attack both problems from inside the FCM template. Figure 6.1 shows the prototype side: a line and a shell are prototypes just as a point is, each with its own distance, and the alternating optimization of section 2.2.5 needs nothing but that distance and a rule to update the prototype from the memberships. A kernel reaches the same end by a different route: it keeps the point prototype but places it in a feature space in which the Euclidean distance is a curved function of the input coordinates, so that one sphere there can enclose a ring.
Figure 6.2 shows the partition side. Along the line through two prototypes, the FCM membership of either cluster crosses at the midpoint and, on the far side of its own prototype, stays above however far away the sample lies, because out there that prototype is always the closer one. A membership that expresses how typical a sample is of a cluster must instead decay with the distance to that cluster alone. This is the possibilistic membership of Krishnapuram and Keller [14], introduced in section 2.2.3 as the partition space . Decoupling the clusters has a price—they may coincide—and two further designs keep the coupling: the possibilistic fuzzy c-means [63] carries both kinds of membership, and Davé’s noise clustering [64] keeps the sum-to-one constraint but adds one more cluster to share with, a noise cluster at the same distance from every sample (fig. 6.3). A sample farther than about from all real prototypes gives most of its membership to the noise cluster, and the real clusters receive only what is left.
6.2 Theory
The notation is that of the book: with rows , memberships in (stored transposed in the code), prototypes with index or , samples with index , squared distances . The reference point throughout is fuzzy c-means (section 3.2.3): the functional (3.3), the membership formula (3.6), and the prototype update (3.7). For each method we state which of the three it changes. Sections 6.2.1 to 6.2.3 change the partition, section 6.2.4 the distance, sections 6.2.5 and 6.2.6 the prototype; section 6.2.7 turns the point prototype into a volume and section 6.2.8 learns the distance as a weighting of the features.
6.2.1 Possibilistic c-means
Krishnapuram and Keller [14] drop the constraint . Without it the FCM functional is minimized by the trivial partition , so a term is added that rewards memberships close to one, with a cluster-specific weight :
|
| (6.1) |
The memberships are now called typicalities and written ; the matrix replaces . Setting the derivative with respect to to zero gives , hence
|
| (6.2) |
The prototype update is (3.7) with typicalities in place of memberships; the typicality replaces (3.6). Three properties follow directly. First, depends on and only, not on the distances to the other prototypes: it is an absolute measure, exactly at , and is the radius of the zone of influence of cluster . Second, no longer controls the fuzziness of a partition but the decay of the typicality: for large distances , so an outlier at three times the radius keeps a typicality of about with and of about with . The follow-up paper [65] therefore recommends around for PCM, smaller than the FCM default. Third, (6.1) is a sum of terms, each involving only the typicalities and the prototype of one cluster: the clusters are optimized independently, PCM amounts to separate mode-seeking procedures, and nothing prevents two of them from converging to the same dense region. These coincident clusters are the characteristic failure of PCM [65], and they are the reason the method is best used as a robust refinement of a partition that FCM has already found rather than as a stand-alone clusterer.
The scales govern the result. The original paper estimates them from a probabilistic partition—in practice from an FCM run, which also initializes the typicalities—as the fuzzy intra-cluster mean squared distance,
|
| (6.3) |
or alternatively as the mean squared distance of the samples whose membership exceeds
an -cut. The
factor widens
() or narrows
() the zones of
influence: too large a
lets the outliers back in and draws the prototypes together, too small a
leaves the tails of a cluster atypical. The original paper already proposes an
optional second phase: after convergence, the scales are re-estimated from the
-cut
of the typicalities and PCM is run once more. The 1996 paper recommends
keeping the scales fixed during the iterations, since re-estimating them from the
typicalities shrinks the clusters. fuzzyclust follows this recommendation:
is
computed once from the FCM partition with the factor eta_scale
and then kept fixed; explicit scales can be passed through eta,
which is also the way to run the second phase. Since the rows of
do
not sum to one, predict_proba returns typicalities, and the hard label
of a
sample that is atypical everywhere means little; the maximal typicality
is a
natural outlier score.
In a nutshell: Possibilistic c-means
- Drops the sum-to-one constraint: the typicality depends only on the distance to prototype relative to the scale ; outliers are atypical of every cluster and do not move the prototypes.
- Same prototype update as FCM; the typicality formula (6.2) replaces the membership formula. sets the decay of the typicality ( is a good value), the zone of influence, estimated once from an FCM run with a factor .
- The clusters do not interact: two prototypes may coincide when the scales are too wide or the groups are close—initialize with FCM, keep , and use PCM as a robust refinement and outlier detector.
6.2.2 Possibilistic fuzzy c-means
Pal, Pal, Keller, and Bezdek [63] keep both descriptions. Every sample has a probabilistic membership (constrained, ) and a typicality (unconstrained), and both enter the functional,
|
| (6.4) |
with weights (not both zero), the FCM exponent for the memberships, an exponent for the typicalities (the paper’s symbol; it plays the role of in PCM), and scales as in PCM. The necessary conditions separate: the memberships follow the FCM formula (3.6), the typicalities the PCM formula with the scale , and the prototypes are weighted by both,
|
| (6.5) |
With the method is FCM, with it is PCM. The membership term keeps the prototypes apart: every sample has to be shared, so two prototypes on the same group would each receive half of its membership mass, while the samples of the other group, which must give their membership to one of the two, pull one of them away. The typicality term keeps the outliers out of the prototype update. The ratio sets the balance, and the paper recommends for noisy data. Two details matter in practice. First, the weight also appears inside the typicality, so raising alone tightens the zone of influence to instead of reproducing PCM; it is the membership weight relative to the effective scale that decides whether the prototypes stay separated, and PFCM tolerates scales several times wider than PCM before clusters coincide (section 6.4.2). Second, with tight scales the typicalities of the core samples themselves fall below one, the weight of the robust term shrinks, and the membership term, which the outliers still contaminate, regains influence; the scales should therefore not be made tighter than the clusters. The scales are set as in PCM, , from the FCM partition that also initializes the method.
In a nutshell: Possibilistic fuzzy c-means
- Memberships (relative, FCM formula) and typicalities (absolute, PCM formula) side by side; both enter the prototype update, with weights and .
- The memberships keep the prototypes apart, the typicalities keep the outliers out; – with scales from FCM is a sound choice, and a large keeps the prototypes separated over a wide range of scales.
-
sets the decay of the typicality as
does in PCM;
also tightens the effective scale .
predict_probareturns memberships,predict_typicalitytypicalities.
6.2.3 Noise clustering
Davé [64] keeps the probabilistic constraint and adds a -th cluster: the noise prototype , which has no position and is defined to be at the same distance from every sample. The functional is the FCM functional with this extra cluster,
|
| (6.6) |
and the Lagrange conditions give the FCM membership formula extended by the noise term in the denominator,
|
| (6.7) |
while the prototypes of the real clusters are the FCM weighted means (3.7). Only the membership formula changes. A sample much closer than to some prototype hardly notices the extra term; a sample farther than from all of them has for every , so its real memberships shrink and the remainder goes to the noise cluster (fig. 6.3). The real clusters still compete for every sample through the constraint, so the coincident clusters of PCM do not occur, and the memberships of the real clusters close around the groups instead of tiling the whole plane. The only parameter is , which acts as a radius beyond which a sample is more noise than member. Davé tied it to the scale of the data through the mean squared distance of all samples to all current prototypes,
|
| (6.8) |
with a user-chosen multiplier . Since that mean is dominated by the distances between the groups, has to be well below one to catch outliers near a group, while a very small starts to declare the tails of the groups noise; – is the range worth scanning, and a fixed can be given when the noise radius is known. When is not given, fuzzyclust re-estimates it from the current prototypes at every iteration, so the functional changes slightly between iterations and need not decrease monotonically. Davé and Krishnapuram [66] later unified the two approaches: PCM is noise clustering with one noise cluster per real cluster and , and both are instances of the robust M-estimators of statistics [67], in which the typicality weight and the noise-reduced membership act as redescending weight functions that give far samples a vanishing influence.
In a nutshell: Noise clustering
- FCM with one extra, position-less prototype at distance from every sample; only the membership formula (6.7) changes.
- Samples farther than from all real prototypes migrate to the noise cluster, the real memberships close around the groups, and the prototypes are protected; the clusters keep competing, so they do not coincide.
- with –, or a fixed ; the noise membership is an outlier score, and noise-dominated samples are labeled . PCM is NC with one noise cluster per real cluster.
6.2.4 Kernel fuzzy c-means
A Mercer kernel is an inner product in a feature space reached by a map that is never computed [68]; the Gaussian kernel is the usual choice. Kernel fuzzy c-means runs FCM in : the functional and the membership formula are those of FCM, and the distance is the feature-space distance to a prototype . Spheres in are curved regions in the input space, which is how a ring or a moon can become one cluster. Following the comparative study of Graves and Pedrycz [69], we distinguish two variants by where the prototype lives.
Prototypes in the feature space. The prototype is the weighted mean of the mapped samples, with —the minimizer of over . Expanding the squared distance and replacing every inner product by a kernel value gives
|
| (6.9) |
the fuzzy counterpart of kernel k-means [70]. The prototype never appears explicitly: it is represented by its weights over the training samples, the kernel matrix is computed once, and (6.9) with a new sample in place of gives its distances and memberships. Any Mercer (positive semidefinite) kernel can be used; the price is memory and prototypes that have no exact pre-image in the input space (fuzzyclust reports the weighted means for plotting only). The code also accepts the sigmoid kernel , which is not positive semidefinite in general: (6.9) can then turn negative, the toolbox clips it at zero, and the result is no longer a distance in any feature space.
Prototypes in the input space. Zhang and Chen [71] keep in the input space and use the distance between the mapped sample and the mapped prototype, which for the Gaussian kernel is
|
| (6.10) |
where the prototype update, obtained by setting the gradient to zero, is a fixed-point iteration in which every sample is additionally weighted by its kernel similarity to the current prototype. The distance saturates at for far samples, so outliers lose their influence: this variant is a robust FCM. The distance is, however, a monotone function of , so its hard partition boundaries are the same bisecting hyperplanes as those of FCM, and it cannot find rings.
For both variants the decisive parameter is , which sets the width of the kernel (a large means a narrow kernel). As the Gaussian kernel becomes linear in the squared distance and kernel FCM collapses to FCM; as all mapped samples become mutually orthogonal, every sample is equally far from every prototype, and the partition is arbitrary. The usable window, where is about the gap between the structures to be separated, spans less than a decade, and inside it the exponent must be close to one, because in the nearly orthogonal feature space a fuzzy exponent spreads the memberships out and makes every prototype the mean of all samples. Graves and Pedrycz found over many data sets that kernel FCM is not uniformly better than FCM and that the kernel parameter is hard to set, and the examples of section 6.4.4 agree. Kernel FCM separates rings that no point prototype can, but for data on clear manifolds the geodesic methods of chapter 7 are the more forgiving tool.
In a nutshell: Kernel fuzzy c-means
- FCM in the feature space of a kernel: same functional and membership formula, the distance is evaluated through kernel values only.
- Feature-space prototypes (weights over the samples) find rings and moons, at memory; input-space prototypes with the Gaussian kernel give a robust FCM whose cells are still convex.
- must match the gap between the structures, and the usable window is narrow; use a nearly crisp , several restarts, and a scan over .
6.2.5 Fuzzy c-varieties and c-elliptotypes
Bezdek, Coray, Gunderson, and Watson [72, 73] replace the point prototype by an -dimensional linear variety (affine subspace)
|
| (6.11) |
which is a point for (FCM), a line for (fuzzy c-lines, FCL), and a hyperplane for . The squared distance of a sample to the cluster is its squared orthogonal distance to the variety, that is, the squared distance to the center minus the squared projections onto the directions,
|
| (6.12) |
and the functional is the c-means functional with this distance. Fixing the prototypes gives the FCM membership formula; fixing the memberships, the center is again the fuzzy mean (3.7), and the directions that minimize are the unit eigenvectors belonging to the largest eigenvalues of the fuzzy scatter matrix of the cluster,
|
| (6.13) |
because is minimized by directing the along the largest spread. The prototype step is a membership-weighted principal component analysis per cluster; the retained eigenvalues measure the spread along the variety, the discarded ones the scatter around it, and their ratio tells how line-like the cluster is. The ellipsoids of Gustafson–Kessel (section 3.2.4) stretch along a line but still measure the position along it; a line prototype measures only the distance from the line, so it separates lines that cross at a point, which GK and FCM have to cut into pieces (fig. 6.19).
The price of a prototype without extent is that collinear groups merge into one cluster: two segments on the same line, however far apart, lie at zero distance from the same line prototype. Bezdek et al. [73] therefore consider convex combinations of the FCV functionals of different dimension, whose prototypes are “elliptotypes” between a point and a line. The two-term combination of and is the fuzzy c-elliptotypes algorithm (FCE): for the same center and direction its distance is the convex combination of the point and the line distance,
|
| (6.14) |
so that the position along the line counts with weight and collinear groups separate; is FCM. The weight should be as small as the data allow. In the example of section 6.4.5, already separates two collinear segments, whereas three crossing lines lose accuracy at and are no longer found from on, because near a crossing the position along a line must not count. Lines through a common point are hard for a random start, since a single run often puts two prototypes on one line, so restarts are advisable.
In a nutshell: Fuzzy c-varieties
- Prototype = -dimensional linear variety (line, plane) through the fuzzy mean, spanned by the leading eigenvectors of the fuzzy scatter matrix; distance = squared orthogonal distance to it; membership formula unchanged.
- Groups samples by the subspace they lie on, not by position: separates crossing lines that FCM and GK cut into pieces; the discarded eigenvalues measure the scatter around the variety.
- Merges collinear groups—a small elliptotype weight of the point distance ( in the example) is the remedy, but already spoils crossing lines; use restarts for lines through a common point.
6.2.6 Fuzzy c-shells and c-spherical shells
A ring has no samples in its interior, so the point prototype at its center is far from every member, and two concentric rings have the same center: no point prototype can tell them apart. Shell clustering describes cluster by a center and a radius and measures the distance of a sample as its deviation from the sphere. The two published algorithms implemented here differ in this distance. Davé’s fuzzy c-shells algorithm (FCS) [74] uses the squared radial (geometric) deviation, and the fuzzy c-spherical shells algorithm (FCSS) of Krishnapuram, Nasraoui, and Frigui [75] the squared algebraic distance,
|
| (6.15) |
both used in the c-means functional with the FCM membership formula. The two algorithms differ in the prototype update. For FCS the necessary conditions,
|
| (6.16) |
are coupled and nonlinear in , and Davé solved them by Newton’s method in every iteration. FCSS avoids this inner iteration: the algebraic distance is with the reparametrized prototype and the regressors , i.e. linear in , so the weighted least-squares minimizer is in closed form,
|
| (6.17) |
one
solve per cluster and iteration. Near the shell the two distances are related by
: the algebraic
distance is about
times the radial deviation, so the same radial deviation counts more on a large
shell than on a small one, and FCSS memberships favor small shells. The bias
shows when nested shells of similar radius have to be separated or when only
arcs are observed; FCS does not have it. fuzzyclust implements both:
algorithm="fcss" is the default, and algorithm="fcs" refines the closed-form
fit in every iteration by newton_steps Gauss–Newton steps on the radial
residuals, a numerically convenient form of Davé’s Newton solution. The
initialization deserves attention. Shell clustering has a notorious local
minimum—one big circle through everything, with the other shells fitting
noise—and a random start rarely escapes it when the shells intersect; the
hardened partition of an FCM run is then a good start, because the FCM
groups lie on different shells. For concentric shells FCM halves every ring
and both shells converge to the mean radius; here the further restarts of
n_init, which start from random point prototypes and are selected by
, find
the rings.
In a nutshell: Fuzzy c-shells
- Prototype = center and radius; distance = deviation from the sphere (radial in FCS, algebraic in FCSS); the membership formula is that of FCM.
- FCSS has a closed-form least-squares update and is the default; FCS needs Newton steps but is unbiased with respect to the shell size (FCSS favors small shells).
- Start from the hardened FCM partition for separate or intersecting shells and use restarts for concentric shells; the results are the radii and the signed radial residuals.
6.2.7 Volume prototypes and adaptive cluster merging
A point prototype measures how far a sample is from the center of a cluster. A sample in the outer part of a large cluster can therefore be closer to the prototype of a small neighboring cluster than to its own, and the membership formula hands it to the neighbor: FCM and GK equalize the clusters, splitting a large diffuse group and letting small groups absorb its pieces (section 3.4.6). Gath–Geva solves the problem with densities and priors at the price of a sensitive iteration. Kaymak and Setnes [43] keep the stable FCM iteration and change the prototype: a volume prototype is a hypersphere (or, in the adaptive norm of GK, a hyperellipsoid) of radius around , and only the distance to its surface counts,
|
| (6.18) |
with or the GK norm (3.10). The functional is the c-means functional with ; the memberships follow the FCM formula (3.6) with in place of , so a sample inside exactly one core belongs fully to that cluster; and the centers are the -weighted means. The radius adapts to the cluster. Kaymak and Setnes derive it from the fuzzy covariance matrix as , the geometric mean of the standard deviations along the principal axes, so that a sphere of that radius has the volume of the cluster, and they multiply it by a factor that grows as the clusters merge. The toolbox uses a simpler estimate, recomputed at every iteration: the membership-weighted mean distance of the data from the center,
|
| (6.19) |
with a fixed scale factor (default one); recovers FCM or GK. A large cluster thus has a large core, its outer members are near the surface of that core, and they stay with it. Cores that grow too large are the failure mode of the method: a core that reaches across a neighboring group swallows it, so should not be raised above one (section 6.4.7).
Adaptive cluster merging. Kaymak and Setnes combine the volume prototypes with merging during the iteration. The algorithm starts with a deliberately large number of clusters. They measure the similarity of two clusters by the fuzzy inclusion measure , symmetrized as , and in every iteration in which the largest similarity has changed by less than a tolerance they merge the most similar pair, provided that its similarity exceeds the threshold , which rises as the number of clusters falls; the iteration continues with one cluster fewer. The toolbox uses a variant that is the similarity criterion of compatible cluster merging (section 4.2.7) built into the iteration: it merges only when the partition has converged for the current number of clusters, it measures the similarity by the ratio of fuzzy intersection and union, (4.17), and its threshold is fixed. Inside the cores the memberships are nearly crisp, which would hide the overlap of two clusters that share a group, so the toolbox evaluates the similarity on the memberships that the center distances alone would give, rescaled to ; two clusters on one group then have –, and the default threshold is .
In a nutshell: Volume prototypes and adaptive merging
- A prototype is a core of radius with zero distance inside; only the distance to the core surface counts, which removes the size-equalizing bias of point prototypes.
- Spherical (Euclidean) or ellipsoidal (GK norm) cores; the radius is re-estimated from the cluster, is FCM/GK; keep .
- Adaptive merging starts with too many clusters and merges similar pairs during the iteration; the final number is insensitive to the starting number.
- Stays within the stable FCM iteration; a lighter alternative to Gath–Geva for clusters of different size.
- Parameters: n_clusters, m, norm, radius, radius_scale, merge, similarity_threshold, gamma, beta; attributes radii_, n_clusters_, merge_history_.
6.2.8 Learning which features matter
The Euclidean distance of FCM gives every feature the same weight. After standardization, a feature of pure noise contributes as much to as a feature that separates the clusters, and enough such features drown the structure. Clusters that are defined by different features, one tight along and another along , cannot be described by one shared norm at all. The two methods of this section learn feature weights together with the partition. Both use the per-feature squared distances and the membership-weighted scatter of a cluster along a feature,
|
| (6.20) |
and both reward a feature along which the members of the clusters scatter little.
Weighted fuzzy c-means. The simpler of the two gives all clusters a common weight vector , , raised to an exponent ,
|
| (6.21) |
This is the fuzzy form of the automated variable weighting that Huang, Ng, Rong, and Li [76] proposed for k-means; Keller and Klawonn [77] had introduced the same kind of functional with one weight for each variable and each cluster, which is the form of SCAD-2 below. The weight update has the form of the FCM membership formula with the total scatter of a feature in place of the distance to a prototype. The weights define the diagonal of a learned norm-inducing matrix , which places the method between FCM with the fixed diagonal norm and GK with its full, cluster-specific norm. As does for the memberships, the exponent controls how sharply the weight concentrates: puts all weight on the feature of smallest scatter, and gives uniform weights.
SCAD. Frigui and Nasraoui’s simultaneous clustering and attribute discrimination [78] gives every cluster its own weights , , as Keller and Klawonn did, so that different clusters can live in different subspaces. SCAD-1 uses the weights linearly and prevents the trivial solution—all weight on the single feature of smallest scatter—by a quadratic term with a cluster-specific coefficient ,
where the weight of a feature rises above when the cluster scatters less along it than on average. Negative weights are set to zero and the row is renormalized, and is re-estimated from the current partition so that the two terms of the functional stay balanced ( is a scale factor, default one). SCAD-2 raises the weights to an exponent instead and needs no ,
|
| (6.23) |
its weights are never exactly zero. In both versions the memberships follow the FCM formula with the weighted distance (or ), and the centers are the -weighted means, since each coordinate of a center minimizes its own weighted sum of squares. The level sets of the weighted distance are axis-parallel ellipsoids, stretched along the features a cluster ignores.
Two cautions apply to both methods. First, the weights reward a small within-cluster scatter, so the features must be on comparable scales: a feature of small variance attracts the weight regardless of its relevance, and even among standardized features one along which the data can be cut into thin slices may attract all of it when the exponent is close to one. Second, the weights are learned from the partition: if the noise features already dominate the first iterations, the partition carries no information and the weights stay uniform. Feature weighting raises the number of noise features that FCM tolerates; it does not replace feature selection when most features are irrelevant (section 6.4.8).
In a nutshell: Weighted fuzzy c-means
- One weight vector for all clusters, learned with the partition: a learned diagonal norm .
- Down-weights features along which the clusters scatter widely (noise features); reports a global feature relevance.
- Standardize first; keep well above one (), otherwise the weight concentrates on one feature.
- Parameters: n_clusters, m, t; attribute feature_weights_.
In a nutshell: SCAD
- A weight vector per cluster: clusters may be defined by different features (subspace clusters), and an irrelevant feature is down-weighted in every cluster.
- SCAD-1: linear weights with a balancing quadratic term, may give exact zeros; SCAD-2: weights with an exponent , never zero, sharper for near one.
- Same cost as FCM plus for the scatters; standardize first.
- Parameters: n_clusters, m, variant, q, delta, delta_scale; attributes feature_weights_, delta_.
6.3 Using it in fuzzyclust
The nine estimators of this chapter live in fuzzyclust.extensions. They derive from BaseFuzzyClusterer and share the common interface: fit, predict, predict_proba, transform, score, the n_init restarts, and pandas input. What predict_proba returns depends on the method and is stated in every docstring: memberships that sum to one (kernel FCM, FCV, shells, volume prototypes, the feature-weighted methods, and PFCM), typicalities that do not (PCM), or real memberships whose rows sum to (noise clustering).
fuzzyclust.extensions.PCM
n_clusters=3, m=2.0, eta=None, eta_scale=1.0, tol, max_iter,
init="fcm"|"random"|"kmeans++"|array, n_init=1, random_state,
verbose.
Attributes cluster_centers_, typicality_ (= membership_, rows not normalized),
labels_, eta_. predict_proba and predict_typicality return typicalities. Use
; eta_scale
is the factor
of (6.3). An init array holds either initial FCM prototypes
or an initial
partition ,
such as the membership_ of a fitted FCM or GK model.
fuzzyclust.extensions.PFCM
n_clusters=3, m=2.0, eta=2.0, a=1.0, b=1.0, gamma=None, gamma_scale=1.0,
tol, max_iter, init="fcm", n_init=1, random_state, verbose.
Attributes membership_ (rows sum to one), typicality_, gamma_, labels_.
predict_proba gives memberships, predict_typicality typicalities.
is FCM,
is
PCM.
fuzzyclust.extensions.NoiseClustering
n_clusters=3, m=2.0, delta=None, delta_scale=0.5, tol, max_iter, init,
n_init=1, random_state, verbose.
Attributes membership_ (real clusters, rows sum to
), noise_membership_,
delta_, labels_ (
for noise-dominated samples). delta_scale is
of
(6.8); predict_noise_membership(X) for new data.
fuzzyclust.extensions.KernelFCM
n_clusters=3, m=2.0, kernel="rbf"|"poly"|"linear"|"sigmoid"|"cosine"|
"laplacian", gamma=None, degree=3, coef0=1.0, prototypes="feature"|
"input", tol, max_iter, init, n_init=1, random_state, verbose.
Kernels through sklearn.metrics.pairwise; gamma=None uses
.
prototypes="input" is the Zhang–Chen variant (Gaussian kernel only).
Attributes membership_, cluster_centers_ (approximate pre-images
for "feature"), gamma_; predict_proba uses the kernelized distance
(6.9).
fuzzyclust.extensions.FuzzyCVarieties
n_clusters=3, m=2.0, n_dims=1, alpha=0.0, tol, max_iter, init,
n_init=1, random_state, verbose.
Attributes cluster_centers_, directions_
(),
scatter_matrices_, covariances_, eigenvalues_ (descending), membership_.
n_dims=0 is FCM, alpha the elliptotype weight of (6.14).
fuzzyclust.extensions.FuzzyCShells
n_clusters=3, m=2.0, algorithm="fcss"|"fcs", newton_steps=2, tol,
max_iter, init="fcm"|"random"|"kmeans++"|array, n_init=1, random_state,
verbose.
Attributes cluster_centers_, radii_, membership_; distances_ and transform
are for
FCSS and
for FCS; radial_deviation(X) gives the signed radial deviation for
both.
fuzzyclust.extensions.VolumePrototypeFCM
n_clusters=3, m=2.0, norm="euclidean"|"adaptive", radius="fuzzy_mean",
radius_scale=1.0, merge=False, similarity_threshold=0.2, gamma=0.0,
beta=1e15, tol, max_iter, init, n_init=1, random_state, verbose.
radius is "fuzzy_mean" (6.19), a number or an array of
fixed
radii; gamma, beta regularize the adaptive norm as in GK. With merge=True,
n_clusters is the starting number and max_iter applies per number of clusters.
Attributes radii_, n_clusters_, merge_history_ (iteration, number of clusters,
pair, similarity), covariances_, norm_matrices_; distances_ and transform
return ,
zero inside the cores.
fuzzyclust.extensions.FeatureWeightedFCM
n_clusters=3, m=2.0, t=2.0, tol, max_iter, init, n_init=1, random_state,
verbose.
t
is the weight exponent of (6.21). Attributes feature_weights_
summing to one, covariances_ (unweighted); distances_ and transform
return the weighted distances.
fuzzyclust.extensions.SCAD
n_clusters=3, m=2.0, variant="scad1"|"scad2", q=2.0, delta=None,
delta_scale=1.0, tol, max_iter, init, n_init=1, random_state, verbose.
delta=None re-estimates by (6.22)
with the factor delta_scale;
a number or an array fixes it (SCAD-1). q is the exponent of SCAD-2. Attributes
feature_weights_
with rows summing to one, delta_, covariances_.
data generators and plot helpers
In fuzzyclust.extensions: make_circles (intersecting circles, arcs, outliers), make_close_blobs (coincident-cluster test case), make_crossing_lines, and make_collinear_segments; the examples also use make_noisy_blobs, make_rings, make_two_moons, and make_different_densities from fuzzyclust.datasets. Plots: plot_typicality(X, T) (scatter colored by , also for ), plot_varieties(X, model), and plot_shells(X, model); the generic fuzzyclust.plotting.plot_membership_contours works for all estimators of the chapter through predict_proba.
The robust variants are drop-in replacements for FCM; the possibilistic ones are seeded by FCM internally:
fcm = FCM(n_clusters=3, random_state=0).fit(X) pcm = PCM(n_clusters=3, m=1.5, random_state=0).fit(X) print(f"scales eta_i = {pcm.eta_.round(2)}") print(f"center error: FCM {center_error(fcm.cluster_centers_):.3f}, PCM {center_error(pcm.cluster_centers_):.3f}")
pfcm = PFCM(n_clusters=3, a=1.0, b=4.0, m=2.0, eta=2.0, random_state=0).fit(X) U, T = pfcm.membership_, pfcm.typicality_ print(f"rows of U sum to one: {np.allclose(U.sum(axis=1), 1.0)}; typicality mass per sample: " f"inliers {T[inliers].sum(axis=1).mean():.2f}, outliers {T[~inliers].sum(axis=1).mean():.2f}")
fcm = FCM(n_clusters=3, random_state=0).fit(X) nc = NoiseClustering(n_clusters=3, delta_scale=0.3, random_state=0).fit(X) n_noise = (nc.labels_ == -1).sum() print(f"noise distance delta = {nc.delta_:.2f}; {n_noise} samples labeled noise, " f"{((nc.labels_ == -1) & ~inliers).sum()} of them true outliers") print(f"center error: FCM {center_error(fcm.cluster_centers_):.3f}, noise clustering {center_error(nc.cluster_centers_):.3f}")
The kernel and shape variants change the distance or the prototype and expose what they find (the kernel parameter, the line orientations, the radii):
fcm_r = FCM(n_clusters=2, random_state=0).fit(rings[0]) kfcm_r = KernelFCM(n_clusters=2, kernel="rbf", gamma=0.3, m=1.2, n_init=5, random_state=0).fit(rings[0]) fcm_m = FCM(n_clusters=2, random_state=0).fit(moons[0]) kfcm_m = KernelFCM(n_clusters=2, kernel="rbf", gamma=15.0, m=1.1, n_init=5, random_state=0).fit(moons[0]) for name, (_, y), f, k in (("rings", rings, fcm_r, kfcm_r), ("moons", moons, fcm_m, kfcm_m)): print(f"{name}: FCM ARI = {adjusted_rand_score(y, f.labels_):.2f}, " f"kernel FCM (gamma = {k.gamma_:g}) ARI = {adjusted_rand_score(y, k.labels_):.2f}")
fcm = FCM(n_clusters=3, n_init=5, random_state=0).fit(X) gk = GK(n_clusters=3, n_init=5, random_state=0).fit(X) fcl = FuzzyCVarieties(n_clusters=3, n_dims=1, n_init=5, random_state=0).fit(X) angles = np.degrees(np.arctan2(fcl.directions_[:, 0, 1], fcl.directions_[:, 0, 0])) % 180 print(f"FCM ARI = {adjusted_rand_score(y, fcm.labels_):.2f}, GK ARI = {adjusted_rand_score(y, gk.labels_):.2f}, " f"fuzzy c-lines ARI = {adjusted_rand_score(y, fcl.labels_):.2f}") print(f"line orientations found: {np.sort(angles).round(1)} degrees (true: 0, 60, 120)")
fcm_r = FCM(n_clusters=2, random_state=0).fit(Xr) fcss_r = FuzzyCShells(n_clusters=2, algorithm="fcss", n_init=5, random_state=0).fit(Xr) fcss_c = FuzzyCShells(n_clusters=3, algorithm="fcss", random_state=0).fit(Xc) print(f"rings: FCM ARI = {adjusted_rand_score(yr, fcm_r.labels_):.2f}, FCSS ARI = " f"{adjusted_rand_score(yr, fcss_r.labels_):.2f}, radii found {np.sort(fcss_r.radii_).round(2)} (true 1, 3)") ce, re = match(fcss_c, true_c, true_r) print(f"circles: FCSS ARI = {adjusted_rand_score(yc, fcss_c.labels_):.2f}, " f"largest center error {ce:.3f}, largest radius error {re:.3f}")
Volume prototypes are a drop-in replacement for FCM, and with merge=True the number of clusters becomes a result:
fcm = FCM(n_clusters=3, n_init=5, random_state=0).fit(X) vp = VolumePrototypeFCM(n_clusters=3, n_init=5, random_state=0).fit(X) print(f"ARI: FCM {adjusted_rand_score(y, fcm.labels_):.2f}, volume prototypes {adjusted_rand_score(y, vp.labels_):.2f}") print("core radii r_i:", np.round(vp.radii_, 2))
vpm = VolumePrototypeFCM(n_clusters=8, merge=True, similarity_threshold=0.2, random_state=0).fit(X) for step in vpm.merge_history_: print(f"iteration {step[’iteration’]:3d}: c = {step[’n_clusters’]} -> merge {step[’pair’]} " f"(S = {step[’similarity’]:.2f})") print(f"final number of clusters: {vpm.n_clusters_}, ARI = {adjusted_rand_score(y, vpm.labels_):.2f}")
The feature-weighted methods return the learned weights next to the partition:
common = dict(n_clusters=3, m=1.3, init="kmeans++", n_init=5, random_state=0) fcm = FCM(**common).fit(X) wfcm = FeatureWeightedFCM(t=3.0, **common).fit(X) # one weight vector for all clusters scad = SCAD(variant="scad1", **common).fit(X) # one weight vector per cluster for name, model in (("FCM", fcm), ("weighted FCM", wfcm), ("SCAD-1", scad)): print(f"{name:13s} ARI = {adjusted_rand_score(y, model.labels_):.2f}") print("global weights:", np.round(wfcm.feature_weights_, 2))
scad2 = SCAD(n_clusters=3, variant="scad2", q=2.0, n_init=5, random_state=0).fit(X_bands) print("SCAD-2 weights (rows: clusters, columns: x1, x2):") print(np.round(scad2.feature_weights_, 2))
6.4 Examples
The first three examples share one data set, generated by make_noisy_blobs: three Gaussian groups of 100 points (, centers to apart) with 60 uniformly scattered outliers. The “center error” reported is the largest distance between an estimated prototype and the sample mean of the matched true group. FCM, pulled outward by the outliers, has a center error of on this data set; without the outliers it would be .
6.4.1 PCM: typicalities, scales, and coincident clusters
With and scales from the FCM run, PCM brings the center error down to (fig. 6.4). The maximal typicality separates the two populations cleanly—median for the inliers, for the outliers—and the 44 samples below a threshold of are all true outliers. The contour maps show the difference in kind: the FCM maximal membership never drops below and rises again far from the data, whereas the PCM typicality is a bump of width around every prototype and vanishes elsewhere. Figure 6.5 shows the same along a probe line through two centers, the empirical counterpart of fig. 6.2. The parameter study (fig. 6.6) varies the scale factor and the exponent. For the center error is below for and ( at ) and rises to at ; for it is already at ; and for the typicality decays so slowly that the outliers keep a mean maximal typicality of at and PCM is worse than FCM for every (center error or more). The coincident-cluster failure (fig. 6.7) appears on a group of 200 points next to a group of 40 at a distance of . With the two prototypes are apart; with they coincide () and the small group is lost. FCM never shows this failure, because its memberships compete.
Open in ColabExample plot_01_pcm_typicality.py in the gallery
6.4.2 PFCM: the trade-off
PFCM with and returns both matrices on the noisy blobs (fig. 6.8): memberships whose rows sum to one and whose contours are the familiar FCM cells, and typicalities that sum to per inlier against per outlier and flag the outliers as PCM does. The study of the weights (fig. 6.9, left) shows the center error dropping from the FCM value as soon as the typicalities enter the update ( gives –). The right panel shows what the memberships buy on the coincident-cluster data: PCM merges the two prototypes at , PFCM with keeps them apart at , halves their distance at , and nearly merges them at , and with the prototypes stay about apart for every scale factor up to ; fig. 6.10 shows the three partitions at . Raising alone does not reproduce PCM, because also tightens the effective scale inside the typicality. The printed study of and the scale factor confirms that a smaller makes the outliers less typical (mean maximal typicality at against at , for ). It also reveals the second effect discussed in section 6.2.2: with tight scales () the center error rises to – for every , because the typicalities of the core samples shrink and the membership term regains weight, whereas with gives .
Open in ColabExample plot_02_pfcm_trade_off.py in the gallery
6.4.3 Noise clustering: the multiplier
With the noise distance comes out at (fig. 6.11): 31 samples are labeled noise, all of them true outliers, the center error is , and the membership contours of the real clusters close around the groups where those of FCM tile the plane. Along the probe line (fig. 6.12) the real memberships decay and the noise membership takes over beyond . The scan over (fig. 6.13) maps the trade-off. With (), 50 of the 60 outliers and one inlier are labeled noise, with a center error of ; declares 128 inliers noise, and the partition of the inliers degrades (ARI ); () labels nothing noise, and the center error climbs back to –. The outliers that escape at moderate are those that fell inside a group. Figure 6.14 shows three of these partitions with the circles of radius . A fixed reproduces FCM exactly (largest noise membership , center error ).
Open in ColabExample plot_03_noise_clustering.py in the gallery
6.4.4 Kernel FCM on rings and moons
The data are two concentric rings of radii 1 and 3 and two moons with a gap of about . FCM reaches adjusted Rand indices of and ; kernel FCM with feature-space prototypes recovers both exactly, with and on the rings and and on the moons, each with five restarts (fig. 6.15). The contours of the maximal membership, evaluated on a grid through the kernelized distance (6.9), follow the rings and bend around the moons. The crosses are the approximate pre-images of the prototypes and play no role in the distances; on the rings both lie near the origin. The scan over (fig. 6.16) shows the narrow window: on the rings only succeeds ( behaves like FCM, fragments the rings), on the moons . At the chosen values is and , the gap between the structures in each case. Figure 6.17 shows the rings at , , and , the last with a mean maximal membership of , that is, an uninformative partition. The exponent matters as much: at the rings are found for , whereas with the agreement drops to and with to , because every feature-space prototype approaches the mean of all mapped samples. A polynomial kernel of degree two or three does not recover the rings (ARI and ). In the quadratic monomials a circle is a hyperplane, and one such hyperplane does separate the two rings, but the outer ring is spread over that space far more widely than the inner one, and a partition that splits it has the smaller ; the linear kernel is FCM. The input-space variant (fig. 6.18) cannot find rings but is a robust FCM: on the noisy blobs its center error is – for between and and below from to , against for FCM.
6.4.5 Fuzzy c-varieties on crossing lines, and the elliptotype
The data are three lines of 80 points through a common point, at
,
, and
(fig. 6.19). FCM tiles the plane into three cells (ARI
);
GK stretches its ellipsoids but cannot align one with each
line without swallowing the centers of the others (ARI
); fuzzy c-lines recovers
the three lines (ARI )
with orientations ,
, and
. The
only ambiguous points are those near the crossing, which are close to all three
lines. The membership contours are bands around the lines, and the eigenvalues
of the scatter matrices show a spread along each line about 600 times larger than
the scatter around it (fig. 6.20). The elliptotype study (fig. 6.21) uses two
collinear segments with a gap and an oblique third segment. Pure fuzzy c-lines
() sees
the collinear segments as one line and spends a prototype on noise (ARI
), and
already separates
them (ARI ).
On the crossing lines, in contrast, the agreement falls from
at
and
at
to
at
and
to or
less for :
where lines cross, the position along the line must not count. The
printed studies show the need for restarts (mean ARI over ten seeds
with one start,
with ten), the
usual role of ,
and two planes in three dimensions recovered with n_dims=2 (ARI
, normals
along the
and
axes).
Open in ColabExample plot_05_fuzzy_c_varieties.py in the gallery
6.4.6 Fuzzy c-shells: radius recovery
FCM halves two concentric rings (ARI ), whereas FCSS with five restarts recovers them with radii and . On three circles of radii , , and , two of which intersect, FCSS started from the FCM-hardened partition finds the centers to within and the radii to within , with an ARI of ; the points near the intersections have shared memberships (fig. 6.22). The membership contours are rings around the fitted circles, and the signed radial residuals of the samples from their own shell are centered at zero, with a spread close to the generating noise level (fig. 6.23). The initialization study (fig. 6.24) shows the two faces of the FCM start. On the concentric rings a single run converges to two circles of radius and through both rings (), five restarts find the rings (), and over ten seeds the FCM start needs ten restarts to succeed every time, while random point prototypes need three. On the intersecting circles, conversely, the FCM start succeeds at once (ARI ) and a single random start fails (ARI ). The comparison of the two algorithms on three concentric rings of radii , , and (fig. 6.25) exposes the small-shell bias of the algebraic distance: both find the rings from the best of ten restarts, but over five seeds FCS reaches a mean ARI of against for FCSS, because the algebraic distance weights the same radial deviation about three times more on the outer ring than on the inner one. On the intersecting circles the two algorithms agree to within in centers and radii for every , and only sets how strongly the memberships are shared at the intersections.
Open in ColabExample plot_06_fuzzy_c_shells.py in the gallery
6.4.7 Volume prototypes on clusters of different size
The script plot_08_volume_prototypes.py returns to the data of section 3.4.6: a large diffuse group of 300 samples next to two small dense ones. FCM splits the large group and gives a slice of it to each small cluster (adjusted Rand index ); with volume prototypes the cores grow to radii , , and , and the large cluster keeps its members (ARI ; fig. 6.26). The membership profile along the line from the center of the large group to that of the smallest one (fig. 6.27) shows the mechanism. The memberships are one inside both cores, and the border between the clusters, where the two memberships cross, lies at of the way instead of for FCM, whose small-cluster prototype has in addition been pulled toward the large group.
Open in ColabExample plot_08_volume_prototypes.py in the gallery
Started with eight clusters, adaptive merging performs five merges, at similarities between and : the first joins the two clusters that share the wider of the two small groups, the other four join pieces of the large group. It ends with three clusters and the same partition as before (fig. 6.28). The parameter study (fig. 6.29) confirms the recommendations of section 6.2.7. The agreement rises with the radius scale from the FCM value at to at and collapses beyond it ( at ), when a core grows over a neighboring group. The merging threshold has a plateau at three clusters from to ; a threshold of stops at five clusters, thresholds of and above do not merge at all, and merges distinct groups down to one cluster. Started with any number of clusters from four to twelve, the merging ends at three.
6.4.8 Feature weights: noise features and subspace clusters
The script plot_07_feature_weighting.py adds six standardized noise features to three groups in two informative features ( for all methods, because in eight dimensions the FCM memberships with are nearly uniform). FCM still finds the groups, but with errors (ARI ); the weighted FCM with and SCAD-1 recover them exactly (fig. 6.30). The global weights of the weighted FCM are and for the informative features and for every noise feature. The SCAD-1 weights show the same pattern in every cluster, but less sharply ( to against to ), because the automatic keeps the weights near uniform unless the scatters differ strongly.
Open in ColabExample plot_07_feature_weighting.py in the gallery
On three clusters that live in different subspaces (a band tight along , a band tight along , and a compact blob), SCAD-2 assigns and of the weight to the feature along which each band is tight and splits the weight of the blob evenly (, ); the level sets of the weighted distances are ellipses stretched along the feature a cluster ignores (fig. 6.31). The partition itself is no better than that of FCM (ARI for both, because the ends of the bands are ambiguous); what SCAD adds is the description of every cluster by its relevant features. The parameter study (fig. 6.32) varies the number of noise features. FCM degrades steadily (ARI with four, with eight), the weighted FCM stays at and SCAD-1 at or above up to eight, and from ten noise features on all methods fail, because the partition of the first iterations is already dominated by noise and the weights are learned from it. The exponent study shows the concentration trap: with or the weighted FCM puts or of the weight on the informative features but cuts the data along a single one of them (ARI ), while every finds the groups.
6.5 Further reading
The possibilistic c-means was introduced in [14], and its insights and recommendations (the exponent, the fixed scales, the coincident clusters) are in [65]; the possibilistic fuzzy c-means is from [63]. Noise clustering is from [64], and the unified view of PCM, noise clustering, and robust statistics [67] is given in [66]. Kernel fuzzy c-means with input-space prototypes is from [71], and its application to incomplete data from [79]; the feature-space variant is the fuzzy counterpart of the kernel k-means of [70]; the comparative study of both against FCM is [69]; and kernels in general are treated in [68]. Fuzzy c-lines and fuzzy c-varieties with their convex combinations are introduced in the two papers [72, 73], within the framework of Bezdek’s book [3]. Fuzzy c-shells is from [74] and the fuzzy c-spherical shells algorithm from [75]; the family of shell algorithms for ellipses and quadrics, together with their possibilistic versions, is surveyed in [80]. The Gustafson–Kessel algorithm [18], with which the c-varieties are compared, is treated in section 3.2.4, and the graph-based methods that find arbitrary shapes without a prototype follow in chapter 7. Volume prototypes and adaptive cluster merging are due to Kaymak and Setnes [43]; the similarity by which the toolbox merges is that of [42]. The weighted fuzzy c-means with global attribute weights is the fuzzy form of the variable-weighted k-means of Huang et al. [76]; cluster-specific weights with an exponent are due to Keller and Klawonn [77], and simultaneous clustering and attribute discrimination, with its regularized and exponent forms, to Frigui and Nasraoui [78].