Fuzzy Clustering and Data Analysis in PythonThe fuzzyclust toolbox

Chapter 12
Beyond a single unsupervised run: partial supervision, co-clustering, collaboration, and ensembles

All algorithms so far take one data matrix, cluster its rows without outside knowledge, and return the partition of one run. This chapter relaxes each of these restrictions. Partial supervision lets a few class labels (Pedrycz and Waletzky) or a few must-link and cannot-link pairs (Grira, Crucianu, and Boujemaa) steer the partition toward the structure the user means; co-clustering (FCCM of Oh, Honda, and Ichihashi; Fuzzy CoDoK of Kummamuru, Dhawale, and Krishnapuram) clusters the rows and the columns of an object–item matrix at once; collaborative clustering (Pedrycz) reconciles the partitions of several data sites that describe the same objects without exchanging their data; and cluster ensembles (Strehl and Ghosh, Punera and Ghosh, and Fred and Jain) combine a library of runs into a consensus that is typically more accurate than its members and more reproducible than a single run, and they read the number of clusters off the agreement of the runs. Partial supervision and collaboration add a term to the c-means functional of chapter 3, co-clustering replaces it by an aggregation criterion, and ensembles combine its results; the methods live in fuzzyclust.semisupervised, .coclustering, .collaborative, and .ensemble.

12.1 Problem and idea

Fuzzy c-means finds the partition that the distance and the prototype shape make optimal, and that partition is not always the one the user wants. Two long parallel bars of points are a simple example (fig. 12.1): with two spherical prototypes the c-means functional prefers a split across the bars, because the variance along the bars dominates the gap between them, whereas the user knows that the bars are the classes. Pedrycz and Waletzky [165] observed that the user often knows the class of a few samples, and added to the functional a term that penalizes the difference between the memberships of these labeled samples and their labels. Since the labeled and the unlabeled samples share the prototypes, a handful of labels moves the prototypes and rotates the whole partition. Labels presuppose an agreed list of classes; a weaker and often cheaper kind of knowledge says only that two samples belong together (must-link) or not (cannot-link): two images show the same scene, two records describe the same customer. Grira, Crucianu, and Boujemaa [166] penalize the expected number of violated pairs and combine the penalty with the competitive agglomeration of Frigui and Krishnapuram [167], which lets an overestimated number of clusters shrink to the number the data and the constraints support.

Figure 12.1

Figure 12.1. Two kinds of partial supervision on two parallel bars that FCM splits across. (a) Labels: a few samples carry a class label, and the supervision term pulls their memberships, and with them the shared prototypes, toward the classes. (b) Pairs: must-link and cannot-link constraints say only whether two samples belong together; their expected violation is penalized.

A second limitation is the data matrix itself. For a document–term matrix, a user–product table, or any other non-negative co-occurrence matrix, the rows and the columns are both entities worth clustering, and a cluster is a pair: a group of documents and the vocabulary that makes them a group (fig. 12.2). Clustering the rows with a distance between sparse count vectors misses this duality. Oh, Honda, and Ichihashi [168] give each co-cluster two membership vectors, one over the objects and one over the items, and maximize the aggregation of the matrix entries that both memberships select; Kummamuru, Dhawale, and Krishnapuram [169] solve the same problem with a different regularizer that scales to large document collections.

Figure 12.2

Figure 12.2. Co-clustering of an object–item matrix (rows and columns reordered). Every co-cluster has a membership vector over the objects (stacked bars, left) and one over the items (bars on top, colored by the co-cluster of largest membership); the dense blocks on the diagonal are the co-occurrences that both memberships select.

The third limitation is organizational. The same objects—patients, customers, production batches—are often described at several data sites by different features, and the raw data cannot be pooled for reasons of confidentiality, size, or ownership. Pedrycz’s collaborative clustering [170] runs fuzzy c-means at every site and lets the sites exchange only their partition matrices (fig. 12.3): each site re-clusters its own data with an additional term that pulls its memberships toward those of the other sites, weighted by a collaboration matrix. The structures are reconciled without moving any data, and how far each site has to move tells how much it disagrees with the rest.

Figure 12.3

Figure 12.3. Collaborative clustering of three data sites. Every site clusters its own features of the same N objects; the sites exchange only their partition matrices, and the collaboration weight α[ii,jj] says how strongly site ii is pulled toward the partition of site jj.

The last limitation is the single run. An alternating-optimization clusterer finds a local optimum that depends on its start, and the partition depends on the sample and on the features it saw; restarts (n_init) keep the run with the lowest objective but discard the information in the others. A cluster ensemble [171] keeps all of them (fig. 12.4). A library of partitions is generated by random starts, sub-samples, feature subsets, or different numbers of clusters. It is summarized by the co-association matrix, the average similarity of the membership vectors of two objects, which needs no matching of cluster labels between the members, and a consensus function partitions the objects from this matrix. Punera and Ghosh [172] showed how to use the soft partitions directly instead of hardening them first. Fred and Jain [173] used the co-association matrix to choose the number of clusters: when the members over-segment the data, the natural groups form the partition of its dendrogram that survives the widest range of thresholds.

Figure 12.4

Figure 12.4. From a library of soft partitions to a consensus. The members may have different numbers of clusters; the co-association matrix compares only co-memberships, so their cluster labels need not be matched, and the consensus function partitions the objects from it.

12.2 Theory

The notation is that of the book: X ∈ ℝN×n with rows xk, memberships μik in U ∈ ℝc×N (stored transposed in the code), prototypes vi, squared Euclidean distances Dik2 = ‖xk −vi‖ 2, index i or j for clusters and k or l for samples. The starting point is fuzzy c-means with m = 2: the functional J = ∑ ⁡ i ∑ kμik2Dik2 (3.3), its membership formula μik = 1∕∑ ⁡ j(Dik2∕Djk2) (3.6), and its prototype update (3.7). The supervised and the collaborative algorithms add a quadratic term to J and keep m = 2, the value for which their papers derive closed-form updates. We treat partial supervision by labels (section 12.2.1) and by pairs (section 12.2.2), co-clustering (section 12.2.3), collaboration (section 12.2.4), and ensembles (sections 12.2.5 and 12.2.6).

12.2.1 Fuzzy c-means with partial supervision

Let bk ∈{0,1} indicate whether sample k is labeled and let fik ≥0, ∑ ⁡ ifik = 1, be its label—the indicator of its class or, more generally, a fuzzy label vector; class j is tied to cluster j, and surplus clusters are unsupervised. Pedrycz and Waletzky [165] minimize

J = ∑ i=1c ∑ k=1Nμ ik2D ik2 + α∑ i=1c ∑ k=1N (μ ik −fikbk )2D ik2
(12.1)

under ∑ ⁡ iμik = 1. The second term measures, in the metric of the clustering, how far the memberships of the labeled samples are from their labels; for an unlabeled sample it reads αμik2Dik2 and merely rescales the c-means term. Setting the derivative of the Lagrangian to zero gives

μik = 1 1 + α [1 + α (1 −bk ∑ j=1cfjk ) ∑ j=1cDik2∕Djk2 + αfikbk] ,
(12.2)

which is the FCM membership for an unlabeled sample and, for a labeled one, the convex combination 1 1+αμikFCM + α 1+αfik: the label is followed to the degree α∕(1 + α). The prototypes are weighted means with the weights of both terms,

vi = ∑ k=1Nwikxk ∑ k=1Nwik ,wik = μik2 + α (μ ik −fikbk )2.
(12.3)

The influence of the labels on the prototypes is not monotone in α. For a labeled sample whose membership has reached its label, the supervision weight α(μik −fik)2 vanishes, while every unlabeled sample carries the weight (1 + α)μik2; a very large α therefore clamps the labeled memberships but lets the unlabeled majority outweigh them in (12.3). The paper recommends α proportional to N∕Nb, the ratio of all samples to the Nb = ∑ ⁡ kbk labeled ones, so that the labeled minority is not ignored; the examples show that moderate values, α ≈1, move the partition most. Because class j is tied to cluster j, a random start that places cluster j next to the samples of another class makes the supervision fight the geometry; starting every supervised prototype at the mean of its labeled samples avoids this. New samples carry no label and receive FCM memberships to the supervised prototypes.

Algorithm

In a nutshell: Fuzzy c-means with partial supervision

  • Adds to the c-means functional the distance-weighted squared difference between the memberships of the labeled samples and their labels; the labels act on the whole partition through the shared prototypes.
  • Labeled memberships are convex combinations of the FCM membership and the label, with weight α∕(1 + α) on the label; unlabeled samples keep the FCM formula.
  • Parameters: the weight α (moderate values move the partition most; N∕Nb is the paper’s rule), the number of clusters (at least the number of classes), and the start (at the labeled means).
  • Use when a few samples of every class are known and the unsupervised optimum differs from the classes; m = 2.

12.2.2 Pairwise constraints and competitive agglomeration

Let M be the set of must-link and C the set of cannot-link pairs (k,l). Under memberships μik, the degree to which a must-link pair is separated is ∑ ⁡ i ∑ j≠iμikμjl and the degree to which a cannot-link pair is together is ∑ ⁡ iμikμil; summed over all pairs, these degrees give the expected number of violated constraints when every sample is assigned at random according to its memberships. Grira, Crucianu, and Boujemaa [166] minimize, with the fuzzy cardinalities Ni = ∑ ⁡ kμik,

J = ∑ i=1c ∑ k=1Nμ ik2D ik2+α [∑ (k,l)∈M ∑ i=1c ∑ j≠iμikμjl+∑ (k,l)∈C ∑ i=1cμ ikμil ]−β∑ i=1cN i2.
(12.4)

The last term is the competitive agglomeration bias of Frigui and Krishnapuram [167]: it rewards large clusters, so the clusters compete for samples and those that lose them can be discarded. Let Cik = ∑ ⁡ l:(k,l)∈M(1 −μil) + ∑ l:(k,l)∈Cμil be the cost of placing sample k in cluster i: the expected number of constraints it would violate there, given the current memberships of its partners. The Lagrange conditions, solved with the cross terms held at their previous values, give the FCM membership plus two corrections,

μik = 1∕Dik2 ∑ j1∕Djk2 + α 2Dik2 (C¯k −Cik ) + β Dik2 (Ni −N¯k ),
(12.5)

where C¯k and N¯k are the means of Cjk and Nj over the clusters, weighted by 1∕Djk2. A cluster in which k violates fewer constraints than on average gains membership, and with β > 0 a cluster larger than average gains membership. The corrections are weighted by 1∕Dik2 and cancel for a sample that is much closer to one prototype than to the others, so the constraints act most strongly on the ambiguous samples near the cluster boundaries. Negative values are clipped and the memberships renormalized, as in competitive agglomeration. The penalty α is in the units of the squared distances. Grira et al. renew it at every iteration so that the constraint term is commensurate with the data term: the mean membership-weighted squared distance, scaled by the ratio of samples to constraints,

α = N |M|+ |C|∑ i,kμik2Dik2 ∑ i,kμik2 .

The automatic rule of fuzzyclust omits the normalization by ∑ ⁡ i,kμik2 and uses α = ∑ ⁡ i,kμik2Dik2∕(|M|+ |C|), the published value times ∑ ⁡ i,kμik2∕N ∈[1∕c,1]; the two agree for a crisp partition. The agglomeration weight follows the schedule of competitive agglomeration,

β(l) = η0e−l∕τ ∑ i,kμik2Dik2 ∑ iNi2 ,
(12.6)

strong at the start and decaying with the iteration l, and clusters whose cardinality Ni falls below a minimum are removed. The prototypes are the FCM means (3.7).

Algorithm

In a nutshell: Pairwise-constrained competitive agglomeration

  • Penalizes the expected number of violated must-link and cannot-link pairs; the membership update shifts membership toward the clusters in which a sample violates fewer constraints.
  • Pairs need no list of classes and are cheap to collect; fewer pairs need a larger penalty, and a few pairs may be satisfied by bending the boundary locally.
  • Optional competitive agglomeration: start with too many clusters, let them compete, and discard the small ones; the usable window of η0 lies between “no competition” and “one cluster takes all”.
  • Parameters: α (or the automatic rule), η0, τ, minimal cardinality; m = 2.

12.2.3 Fuzzy co-clustering of objects and items

Let R = [rkj] ∈ ℝ≥0N×M be an object–item matrix (counts, frequencies, TF-IDF weights). A co-cluster i has object memberships uik and item memberships wij, with the constraints ∑ ⁡ iuik = 1 for every object (an object is shared among the co-clusters, as in FCM) and ∑ ⁡ jwij = 1 for every co-cluster (each co-cluster distributes one unit of membership over the items). The quantity to be maximized is the aggregation degree

∑ i=1c ∑ k=1N ∑ j=1Mu ikwijrkj = ∑ i,kuikaik = ∑ i,jwijbij,aik = ∑ jwijrkj, bij = ∑ kuikrkj,
(12.7)

large when the objects of a co-cluster cooccur with its items. The aggregation aik is a weighted mean of the row of object k over the items of co-cluster i, and bij is a weighted sum of the column of item j over the objects of the co-cluster. The aggregation degree alone is linear in each membership set and is maximized by crisp, degenerate memberships, with the whole item membership of a co-cluster on its single most frequent item. Oh, Honda, and Ichihashi [168] regularize both sets by their entropies, the device of Miyamoto and Mukaidono for fuzzy c-means [23], and maximize

JFCCM = ∑ i,k,juikwijrkj −λu ∑ i,kuik log ⁡ uik −λw ∑ i,jwij log ⁡ wij.
(12.8)

The necessary conditions are soft-max assignments,

uik = exp ⁡ (aik∕λu) ∑ l=1c exp ⁡ (alk∕λu),wij = exp ⁡ (bij∕λw) ∑ l=1M exp ⁡ (bil∕λw),
(12.9)

alternated until the object memberships settle. The weights are measured in the units of the aggregations they temper: λu like a typical entry of R, and λw like an entry summed over the objects of a co-cluster, so its scale grows with the size of the data. A small λ makes the corresponding memberships crisp; a large one drives them to the uniform values 1∕c and 1∕M. New objects receive memberships by the first formula with the fitted item memberships.

Algorithm

In a nutshell: FCCM

  • Clusters rows and columns of a non-negative co-occurrence matrix at once; a co-cluster is a group of objects with the items that characterize it.
  • Maximizes the aggregation degree regularized by the entropies of both membership sets; the updates are soft-max assignments, and no distance between rows is needed.
  • Parameters: λu (in the units of a row mean) and λw (in the units of a column sum over a co-cluster); outside a window of λw the solution degenerates.
  • Use for document–term, user–item, or other count tables; restarts (n_init) keep the largest objective.

Kummamuru, Dhawale, and Krishnapuram [169] replace the entropies by quadratic regularizers,

JCoDoK = ∑ i,k,juikwijrkj −Tu ∑ i,kuik2 −T w ∑ i,jwij2.
(12.10)

The necessary conditions are then linear: a membership is the uniform value plus a multiple of the deviation of its aggregation from the mean aggregation,

uik = 1 c + 1 2Tu (aik − 1 c∑ l=1ca lk ),wij = 1 M + 1 2Tw (bij − 1 M∑ l=1Mb il ),
(12.11)

followed by clipping at zero and renormalization. No exponentials are evaluated, which removes the overflow of (12.9) for large aggregations, and the clipping sets the item memberships of the irrelevant terms to exactly zero, which gives a sparse and readable result for document collections with large vocabularies.

Algorithm

In a nutshell: Fuzzy CoDoK

  • The FCCM aggregation with quadratic instead of entropy regularizers: linear updates, clipping instead of exponentials.
  • Sparse item memberships (irrelevant items get zero), no overflow for large aggregations, and a wider usable range of the item weight Tw.
  • Parameters: Tu and Tw in the units of FCCM’s λu and λw.

12.2.4 Collaborative fuzzy clustering

The same N objects are described at P sites by data X[ii] ∈ ℝN×nii, ii = 1,…,P. All sites look for c clusters, with memberships μik[ii], prototypes vi[ii] in their own feature spaces, and squared distances Dik2[ii]. The collaboration matrix α[ii,jj] ≥0 states how strongly site ii takes the partition of site jj into account. Pedrycz [170] lets site ii minimize

Q[ii] = ∑ i,kμik2[ii]D ik2[ii] + ∑ jj≠iiα[ii,jj]∑ i,k (μik[ii] −μik[jj] )2D ik2[ii],
(12.12)

in which the other sites enter only through their memberships. With α¯[ii] = ∑ ⁡ jj≠iiα[ii,jj] and the communicated memberships

φik[ii] = ∑ jj≠iiα[ii,jj]μik[jj] 1 + α¯[ii] ,
(12.13)

the Lagrange conditions give

μik[ii] = φik[ii] + 1 −∑ l=1cφlk[ii] ∑ l=1cDik2[ii]∕Dlk2[ii], (12.14) vi[ii] = ∑ kwik[ii]xk[ii] ∑ kwik[ii] , (12.15) wik[ii] = μik2[ii] + ∑ jj≠iiα[ii,jj] (μik[ii] −μik[jj] )2

The membership is a convex combination of the other sites’ memberships, with total weight α¯∕(1 + α¯), and of the site’s own FCM membership; the prototype weights add to the FCM weight the disagreement with the other sites. The algorithm has two phases. In the first, every site runs FCM independently, and the clusters of the sites are matched by the Hungarian algorithm on the membership overlap U[1]U[jj]T, because the sites must refer to the same clusters. In the second, the sites iterate synchronously: each updates its prototypes and memberships by (12.14) and (12.15) from the partitions the others communicated in the previous round, until no membership changes by more than 𝜖. A site whose row of the collaboration matrix is zero keeps minimizing its plain FCM functional in the second phase, so it stays at its phase-one solution up to the tolerance of the first phase. The collaboration matrix need not be symmetric: a site may listen without being listened to.

Two quantities summarize the result. The distance between the partitions of two sites, 1 N ∑ ⁡ i,k(μik[ii] −μik[jj])2, or their fuzzy Rand index (4.19), measures how well the sites agree; the mean absolute change of a site’s memberships from the first to the second phase measures how much the site had to give in, and therefore how much its view of the objects differed from the others’.

Algorithm

In a nutshell: Collaborative fuzzy clustering

  • The same objects are described at several sites by different features; the sites exchange only partition matrices, never data.
  • Each site minimizes its FCM functional plus the distance-weighted disagreement with the other sites’ memberships; memberships become convex combinations of own and communicated memberships.
  • The collaboration matrix sets how much site ii trusts site jj and may be asymmetric; a larger weight pulls the partitions together monotonically.
  • The membership change of a site from the independent to the collaborative phase locates the sites that disagree; m = 2.

12.2.5 Cluster ensembles and consensus functions

Consider a library of Q soft partitions U(1),…,U(Q) of the same N objects; member q has cq clusters and membership vectors μk(q) ∈ ℝcq. In fuzzyclust the ensemble generates the library itself: every member is the base clusterer (fuzzy c-means by default), fitted with its own random start on a random share of the samples and of the features and with a number of clusters drawn from a given set, and the memberships of all samples come from its predict_proba. Strehl and Ghosh [171] call the task of combining such partitions without access to the data knowledge reuse; the members’ cluster labels are arbitrary, so a consensus function must be invariant to them.

The co-association matrix. Comparing objects rather than clusters makes the labels irrelevant. The soft co-association of two objects is the library average of the similarity of their membership vectors,

skl = 1 Q∑ q=1Q ⟨μk(q),μl(q) ⟩ ‖μk(q)‖ ‖μl(q)‖ orskl = 1 Q∑ q=1Q ∑ i=1cq μik(q)μ il(q).
(12.16)

For crisp members both equal the fraction of members that put k and l into the same cluster, which is the evidence accumulation matrix of Fred and Jain [173] and the similarity of the CSPA algorithm of Strehl and Ghosh. For soft members the inner product (right) is the probability that two independent draws from the membership vectors land in the same cluster; it is below one even for k = l, and the more so the fuzzier the member. The cosine (left, the default) normalizes the membership vectors of every member, so that an object is fully co-associated with itself and with every object that has the same membership vector; the scale of S = [skl] then does not depend on the fuzziness or the number of clusters of the members. The matrix S is symmetric with entries in [0,1].

Consensus functions. Five ways to obtain c consensus clusters are implemented. (i) FCM on the rows of S: the row sk is the profile of object k’s co-associations with all objects, and objects of one consensus cluster have similar profiles; fuzzy c-means with m = 2 clusters these N-dimensional rows. In such a high dimension FCM from a random partition drifts to the trivial fixed point of all prototypes at the grand mean, so the prototypes are seeded with k-means++. (ii) Spectral partitioning [174] of the graph with adjacency S; it takes the place of the METIS partitioner [175] used in CSPA and in the soft sCSPA of Punera and Ghosh [172]. (iii) Hierarchical clustering of the distance 1 −skl (evidence accumulation, section 12.2.6). (iv) The soft meta-clustering algorithm sMCLA [172]: every cluster of every member is a hyperedge, its membership vector over the N objects; the ∑ ⁡ qcq hyperedges are grouped into c meta-clusters by the similarity of these vectors (fuzzyclust uses their cosine similarity and spectral partitioning in place of METIS), every meta-cluster is collapsed into its mean membership vector, and an object’s consensus membership is its collapsed membership normalized over the meta-clusters. (v) Information-theoretic k-means ITK [172]: the concatenated membership vectors of an object, divided by Q, form a distribution pk over all clusters of the library, and k-means with the Kullback–Leibler divergence KL(pk∥mi) as distortion partitions these distributions; its centroids mi are arithmetic means, and restarts keep the smallest total divergence. The hard consensus functions (ii), (iii), and (v) receive soft memberships in the space of the co-associations: the mean row of every consensus cluster is its prototype zi = ∑ ⁡ k∈isk∕|i|, and every object receives the FCM membership of its row,

μik∗ = 1 ∑ j=1c ‖sk −zi‖ 2∕ ‖sk −zj‖ 2,
(12.17)

the same rule as for (i), so that all consensus memberships are on one scale. A new object is passed through every member, its co-associations with the training objects follow from (12.16), and (12.17) (or the meta-clusters of sMCLA) gives its consensus membership. The classical hard consensus functions CSPA and MCLA of Strehl and Ghosh are (ii) and (iv) applied to crisp members.

Algorithm

In a nutshell: Fuzzy cluster ensemble

  • Combines a library of soft partitions (random starts, sub-samples, feature subsets, various c) through the co-association matrix, which needs no matching of cluster labels.
  • The consensus is typically better than the average member and far more reproducible than a single run; most of the gain comes with the first few members.
  • Parameters: library size, sample and feature fractions, member cluster numbers, consensus function (FCM on the rows of S, spectral, hierarchical, sMCLA, ITK), similarity (cosine or inner product).
  • Costs Q fits plus an N ×N matrix; use for unstable clusterers, weak views of the data, or to choose c (next section).

12.2.6 Evidence accumulation and the lifetime criterion

Fred and Jain [173] use the co-association matrix of members that deliberately over-segment the data: k-means runs with many more clusters than expected and a different number for each run. Objects of one natural group are split differently by different members but stay together in most of them; objects of different groups are rarely together. The distance dkl = 1 −skl is clustered hierarchically (single or average link); let h1 ≤h2 ≤⋯ ≤hN−1 be the merge heights of the dendrogram and hN = 1 the largest possible distance. Cutting the dendrogram at a threshold in [hN−k,hN−k+1) yields exactly k clusters, and the length of this interval,

τk = hN−k+1 −hN−k,k = 1,2,…,
(12.18)

is the lifetime of the k-cluster partition. The chosen number of clusters is the one of longest lifetime, the partition least sensitive to the choice of the threshold. The criterion inherits the behavior of the linkage. Average link copes with soft members; single link merges two groups as soon as one chain of objects connects them, and since the co-associations of soft members between neighboring groups never vanish, the one-cluster partition then lives longest. The members must also over-segment: a member with fewer clusters than groups merges some groups, and no amount of evidence separates what no member separates.

Algorithm

In a nutshell: Evidence accumulation

  • The chosen number of clusters is that of the partition of the co-association dendrogram that persists over the widest range of thresholds.
  • Needs over-segmenting members; beyond that, the exact range of member cluster numbers hardly matters.
  • Average link works with soft members; single link can be defeated by chains of intermediate objects.
  • Parameters: range of member cluster numbers, linkage, largest k considered.

12.3 Using it in fuzzyclust

The four sub-packages follow the conventions of the toolbox. The supervised estimators derive from BaseFuzzyClusterer and take the supervision as arguments of fit; the co-clustering estimators and the ensemble are scikit-learn clusterers with fit(X); the collaborative estimator takes a list of data sites. All accept pandas input and have a random_state, and their partitions can be compared with the fuzzy Rand indices of fuzzyclust.validity (section 4.2.8).

fuzzyclust.semisupervised.SemiSupervisedFCM

n_clusters=3, alpha=1.0|"auto" (N∕Nb), m=2.0 (fixed), tol, max_iter, init="labels"|"random"|"kmeans++"|array, n_init, random_state, verbose.
fit(X, y) with y a label vector (-1 = unlabeled) or a label-membership matrix (N,c) whose zero rows mark the unlabeled samples. Attributes membership_, cluster_centers_, labels_, classes_, label_mapping_ (class of every cluster, -1 for unsupervised ones), labelled_mask_, label_membership_, alpha_, covariances_; methods predict_classes(X), score_labels(X,  y).

fuzzyclust.semisupervised.PairwiseConstrainedFCM

n_clusters=3, alpha=1.0|"auto", agglomeration=0.0 (η0), agglomeration_decay=10.0 (τ), min_cardinality=1.0, m=2.0 (fixed), tol, max_iter, init, n_init, random_state, verbose.
fit(X, must_link=pairs, cannot_link=pairs). Attributes n_clusters_, membership_, cluster_centers_, must_link_, cannot_link_, must_link_satisfied_, cannot_link_satisfied_, alpha_, cardinalities_. Utilities constraint_satisfaction(labels, must_link, cannot_link), check_pairwise_constraints; generators make_partially_labeled_pair, make_partial_labels, make_pairwise_constraints; plots plot_label_propagation, plot_pairwise_constraints.

fuzzyclust.coclustering.FCCM, FCoDoK

n_clusters=3, lambda_u=1.0 (λu or Tu), lambda_w=1.0 (λw or Tw), tol, max_iter, init="random"|"kmeans++"|array, n_init (largest objective kept), random_state, verbose.
fit(R) with a non-negative matrix. Attributes membership_ (N,c), item_membership_ (M,c), labels_, item_labels_, aggregation_, objective_, objective_history_; transform returns the aggregations aik, predict_proba the object memberships of new rows. Generator make_block_matrix; plots plot_coclusters (reordered heat map), plot_item_memberships.

fuzzyclust.collaborative.CollaborativeFCM

n_clusters=3, alpha=0.5 (scalar or P ×P matrix), m=2.0 (fixed), tol, max_iter, init, n_init, random_state, verbose.
fit([X_1, ..., X_P]). Attributes (lists over the sites) memberships_, cluster_centers_, labels_, independent_memberships_, independent_centers_; arrays alpha_, objective_, objective_history_, partition_distances_, collaboration_change_, consensus_membership_. Methods predict_proba, predict, transform on lists of sites, site_agreement(index=fuzzy_rand_index). Utility align_partitions; generator make_collaborative_sites; plots plot_site_partitions, plot_collaboration_trajectory.

fuzzyclust.ensemble.FuzzyClusterEnsemble

n_clusters=3|None (lifetime criterion), base_estimator=None (FCM; any clusterer with predict_proba), n_estimators=10, base_n_clusters=None|int| sequence, sample_fraction=1.0, feature_fraction=1.0, consensus="fcm"| "spectral"|"hierarchical"|"smcla"|"itk", linkage="average"| "single"|"complete", similarity="cosine"|"product", max_clusters=20, random_state, verbose.
Attributes base_estimators_, base_memberships_, base_feature_subsets_, coassociation_, consensus_membership_ (= membership_), labels_, n_clusters_, consensus_centers_, lifetimes_, linkage_, meta_cluster_labels_, base_agreement_. Functions coassociation_matrix, evidence_accumulation, soft_mcla, information_theoretic_kmeans, cspa, mcla, stability_curve(X,  n_estimators_grid, n_repeats, index); generator make_overlapping_blobs; plots plot_coassociation, plot_lifetimes.

Partial labels and pairwise constraints are passed to fit:

fcm = FCM(n_clusters=2, random_state=0).fit(X) 
ssfcm = SemiSupervisedFCM(n_clusters=2, alpha=1.0, random_state=0).fit(X, y_partial) 
print(f"FCM ARI = {adjusted_rand_score(y, fcm.labels_):.2f}, " 
      f"SSFCM ARI = {adjusted_rand_score(y, ssfcm.labels_):.2f}, " 
      f"accuracy of the class prediction = {ssfcm.score_labels(X, y):.2f}")
   
must_link, cannot_link = make_pairwise_constraints(y, n_must_link=50, n_cannot_link=50, random_state=0) 
fcm = FCM(n_clusters=2, random_state=0).fit(X) 
pcca = PairwiseConstrainedFCM(n_clusters=2, alpha=5.0, random_state=0) 
pcca.fit(X, must_link=must_link, cannot_link=cannot_link) 
print(f"FCM  ARI = {adjusted_rand_score(y, fcm.labels_):.2f}") 
print(f"PCCA ARI = {adjusted_rand_score(y, pcca.labels_):.2f}, satisfied must-link " 
      f"{pcca.must_link_satisfied_:.2f}, cannot-link {pcca.cannot_link_satisfied_:.2f}")
   

A co-clustering returns memberships for the rows and for the columns:

fccm = FCCM(n_clusters=4, lambda_u=0.1, lambda_w=20.0, n_init=5, random_state=0).fit(R) 
print(f"FCCM documents ARI = {adjusted_rand_score(doc_topic, fccm.labels_):.2f}, " 
      f"topical terms ARI = {adjusted_rand_score(term_topic[topical], fccm.item_labels_[topical]):.2f}")
   

The collaborative estimator takes the sites as a list and reports how much every site moved:

independent = CollaborativeFCM(n_clusters=3, alpha=0.0, random_state=0).fit(Xs) 
collab = CollaborativeFCM(n_clusters=3, alpha=3.0, random_state=0).fit(Xs) 
for name, model in (("independent", independent), ("alpha = 3", collab)): 
    print(f"{name:12s}: ARI per site = " 
          + ", ".join(f"{adjusted_rand_score(y, lab):.2f}" for lab in model.labels_) 
          + f";  membership change = {np.round(model.collaboration_change_, 3)}")
   

An ensemble is configured by its library and its consensus function; with n_clusters=None it chooses the number of clusters, and stability_curve measures its reproducibility:

ens = FuzzyClusterEnsemble(n_clusters=4, n_estimators=20, sample_fraction=0.3, feature_fraction=0.34, 
                           consensus="fcm", random_state=0).fit(X) 
members = [adjusted_rand_score(y, U.argmax(axis=1)) for U in ens.base_memberships_] 
print(f"members: mean ARI = {np.mean(members):.2f}, best = {np.max(members):.2f};  " 
      f"consensus ARI = {adjusted_rand_score(y, ens.labels_):.2f}")
   
ens = FuzzyClusterEnsemble(n_clusters=None, base_n_clusters=range(6, 13), n_estimators=30, linkage="average", 
                           random_state=0).fit(X) 
print(f"lifetime criterion: {ens.n_clusters_} clusters, ARI = {adjusted_rand_score(y, ens.labels_):.2f}") 
print("lifetimes of k = 1..8:", np.round(ens.lifetimes_[:8], 3))
   
table = stability_curve(X10, n_estimators_grid=(1, 3, 10, 20), n_repeats=5, n_clusters=10, 
                        random_state=0, index=fuzzy_adjusted_rand_index) 
print(table.round(3))
   

12.4 Examples

12.4.1 How many labels, how much weight?

The two parallel bars of 150 points each (fig. 12.5) are split by FCM across the bars (ARI 0.39). With 10 % labeled samples and α = 1 the prototypes move toward the bars and the ARI rises to 0.60; 87% of all samples are assigned to their class. Plotted against the position along the bars (fig. 12.6), the memberships are clear in the middle of the bars and drift toward 0.5 at their ends, where both prototypes are almost equally far away. At the ends spherical prototypes cannot tell the bars apart, and that is where the remaining errors lie. The study of fig. 12.7 varies the label fraction from 1 to 30 % and the weight. Up to α = 3 more labels always help (α = 1: from 0.38 at 1 % to 0.77 at 30 %), while the weight acts non-monotonically: α = 10 never exceeds 0.56, and the paper’s rule α = N∕Nb, which gives a large weight when labels are scarce, does no better than α = 10 up to 10 % labels and approaches α = 3 only at 30 % (0.69). The reason is the weighting in (12.3): once the labeled memberships match their labels, their supervision weight vanishes, while the unlabeled samples are weighted by 1 + α.

Figure 12.5

Figure 12.5. FCM splits the two bars across (left); with 10 % labeled samples (large markers) and α = 1 the partition turns toward the bars (right).

Open in ColabExample plot_01_ssfcm_partial_labels.py in the gallery

Figure 12.6

Figure 12.6. Membership in the upper-bar cluster along the bars: clear in the middle, ambiguous at the ends; labeled samples (black) are pulled toward their label.

Figure 12.7

Figure 12.7. Agreement with the true bars against the share of labeled samples for several weights α: more labels help, and moderate weights help most.

12.4.2 Must-link, cannot-link, and competitive agglomeration

On the same bars, 50 must-link and 50 cannot-link pairs drawn from the classes are given (fig. 12.8). FCM violates 24 of them; PCCA with α = 5 satisfies all and reaches an ARI of 0.95. The penalty study (fig. 12.9) shows that the fewer the pairs, the larger the penalty needed: 100 pairs of each kind reach an ARI of 0.99 at α = 2, 25 pairs need α = 10, and 10 pairs reach only 0.7 even at α = 20, although nine tenths of them are satisfied already at α = 0.5, because a handful of pairs can be honored by bending the boundary locally. The automatic penalty, renewed as the FCM term over the number of constraints, ends at α = 4.3 for 100 pairs and at 42 for 10 pairs, and gives ARIs of 0.99 and 0.72. Started with eight clusters on three Gaussian groups (fig. 12.10), competitive agglomeration keeps all eight for η0 ≤1, ends with exactly three for η0 from 5 to 20 at the default decay τ = 10, and collapses to one cluster at η0 = 40; a longer competition (τ = 30) shifts the window toward weaker weights.

Figure 12.8

Figure 12.8. The 24 constraints that FCM violates (top) and the partition of PCCA with α = 5, which satisfies all 100 constraints (bottom); green: must-link, vermilion dashed: cannot-link.

Open in ColabExample plot_02_pcca_pairwise_constraints.py in the gallery

Figure 12.9

Figure 12.9. Agreement with the classes (left) and share of satisfied constraints (right) against the penalty α for 10 to 100 pairs of each kind.

Figure 12.10

Figure 12.10. Competitive agglomeration from eight clusters: final number of clusters against η0 for three decays (left) and the three clusters found with η0 = 5 (right).

12.4.3 Co-clustering a document–term matrix

A synthetic corpus of 180 documents in four topics of 30 to 60 documents, with topic vocabularies of 15 to 30 terms and 20 general terms, has Poisson counts of mean 3 inside the topic blocks and 0.3 elsewhere; rows and columns are shuffled (fig. 12.11, left). FCCM with λu = 0.1 and λw = 20 recovers the topics of the documents and of the topical terms exactly (both ARIs 1.0), and the matrix reordered by the co-clusters shows the four blocks (right). The scaled item memberships (fig. 12.12) rank every topic’s own terms by frequency and give the general terms a membership near zero in all co-clusters. The grid study (fig. 12.13) shows the units of the two weights at work. A small λu gives nearly crisp document memberships, λu ≥1 fuzzy ones, and λu = 3 dissolves them. For λw there is a window, from 20 to 200 for λu ≤0.1, below which a co-cluster concentrates on a few frequent terms and above which the term memberships become uniform; the window closes from above as λu grows (20–50 at λu = 0.3, only 20 at λu = 1). Fuzzy CoDoK recovers the topics exactly for Tu ≤0.3 and every Tw from 20 to 1000, and its clipped item memberships list the topic vocabularies with exact zeros elsewhere (fig. 12.14).

Figure 12.11

Figure 12.11. A shuffled document–term matrix (left) and the same matrix reordered by the four FCCM co-clusters (right).

Open in ColabExample plot_03_fccm_document_term.py in the gallery

Figure 12.12

Figure 12.12. Scaled term memberships of the four co-clusters: every topic owns its vocabulary, and the general terms (right of the dotted line) belong to none.

Figure 12.13

Figure 12.13. FCCM on a grid of the two entropy weights: agreement with the topics (left) and crispness of the document memberships (right).

Figure 12.14

Figure 12.14. Fuzzy CoDoK: the 40 terms of largest scaled membership, grouped by co-cluster.

12.4.4 Three collaborating sites

Three sites describe the same 300 objects in three groups with feature spreads 0.6, 1.2, and 1.8, and at the third site 15 % of the objects are moved to another group (fig. 12.15). Independently, the sites reach ARIs of 1.00, 0.93, and 0.37. With α = 3 the clear site keeps its partition, the second improves to 0.98, and the third follows the majority even on its moved objects (ARI 0.98 with the common groups), so that its clusters now overlap in its own feature space. The study of fig. 12.16 shows the fuzzy Rand index between every pair of sites rising monotonically with α toward one, site 3 joining the majority from α ≈1, and site 3 giving in most (mean membership change 0.13 against 0.10 and 0.07); every site moves, because a membership pulled toward the others is also a softer one. Asymmetric collaboration matrices, whose results the example prints, give trust selectively: when only site 3 listens, sites 1 and 2 keep their independent partitions and site 3 is corrected alone (ARI 1.00); when only the clear site 1 listens, it is pulled toward the noisier sites and drops to 0.91.

Figure 12.15

Figure 12.15. The three sites clustered independently (top) and with collaboration α = 3 (bottom); colors are the clusters matched across the sites.

Open in ColabExample plot_04_collaborative_sites.py in the gallery

Figure 12.16

Figure 12.16. Against the collaboration weight: fuzzy Rand index between the sites (left), agreement of every site with the true groups (middle), and mean membership change of every site (right).

12.4.5 A library beats a single run

Four overlapping groups in six dimensions are clustered by an ensemble of 20 FCM members, each seeing two random features and 30 % of the samples (fig. 12.17). The members reach a mean ARI of 0.37 and at best 0.77; their consensus reaches 0.86, better than every member because the members err in different directions, and close to the 0.91 of one FCM run on all data. The co-association matrix ordered by the consensus shows the four blocks. Over the library size (fig. 12.18), a single member is as weak as any, three to ten members bring most of the gain, and the five consensus functions behave alike, with sMCLA a few points behind from ten members on. Accuracy needs ground truth, but reproducibility does not: on ten overlapping groups in the plane, FCM with ten clusters lands in different local optima, and the fuzzy adjusted Rand index between repeated consensus partitions rises from 0.62 ±0.26 for single runs to 0.86 ±0.04 for libraries of 20 (fig. 12.19).

Figure 12.17

Figure 12.17. Twenty weak members and their consensus: distribution of the member ARIs with the consensus and the member mean (left), co-association matrix ordered by the consensus (right).

Open in ColabExample plot_05_ensemble_consensus.py in the gallery

Figure 12.18

Figure 12.18. ARI of the consensus against the library size for the five consensus functions.

Figure 12.19

Figure 12.19. Fuzzy adjusted Rand index between repeated consensus partitions against the library size: the ensemble makes an unstable clusterer reproducible.

12.4.6 Choosing the number of clusters by the lifetime

Five groups are clustered by 30 FCM members with 6 to 12 clusters each (fig. 12.20). The average-link dendrogram of 1 −skl gives the five-cluster partition a lifetime of 0.53, against at most 0.06 for any other number, and the consensus recovers the groups exactly. The top of the dendrogram (fig. 12.21) shows where this comes from: below the band the groups fall apart into the fragments the members produced, and above it neighboring groups merge. The study of fig. 12.22 varies the members’ numbers of clusters and the linkage. Members with fewer clusters than groups (2 to 4) give three clusters, every over-segmenting range gives five with average link, and single link always returns one cluster, because chains of objects between the groups merge them at a low height. The repetition on four and six groups, printed by the example, finds four groups from every range and six groups from members with 6 to 12 or 10 to 20 clusters (five from members with 4 to 8).

Figure 12.20

Figure 12.20. Evidence accumulation on five groups: the consensus with the number of clusters chosen by the lifetime (left), the co-association matrix (middle), and the lifetimes of k clusters (right).

Open in ColabExample plot_06_ensemble_lifetime.py in the gallery

Figure 12.21

Figure 12.21. Top of the average-link dendrogram of the co-association distances; the band is the range of thresholds that yields five clusters.

Figure 12.22

Figure 12.22. Number of clusters chosen by the lifetime against the range of the members’ numbers of clusters, for average and single link.

12.5 Further reading

Partial supervision by labels goes back to Pedrycz and Waletzky [165]; pairwise constraints combined with competitive agglomeration are due to Grira, Crucianu, and Boujemaa [166], and competitive agglomeration itself to Frigui and Krishnapuram [167]. Fuzzy co-clustering with entropy regularization was introduced by Oh, Honda, and Ichihashi [168], building on Miyamoto and Mukaidono [23], and the quadratic variant by Kummamuru, Dhawale, and Krishnapuram [169]. Collaborative clustering is due to Pedrycz [170]. Cluster ensembles were framed by Strehl and Ghosh [171] (CSPA, MCLA, and the METIS graph partitioner of Karypis and Kumar [175]), extended to soft partitions by Punera and Ghosh [172] (sCSPA, sMCLA, ITK), and turned into a criterion for the number of clusters by Fred and Jain [173]; the spectral partitioning follows Ng, Jordan, and Weiss [174]. Partitions are compared with the fuzzy Rand indices of Hüllermeier et al. [45] and Campello [46] and the chance correction of Hubert and Arabie [44]; the c-means functional is that of Bezdek [3], and Jain and Dubes [4] cover hierarchical clustering in general.