fuzzyclust.ensemble.FuzzyClusterEnsemble#

class fuzzyclust.ensemble.FuzzyClusterEnsemble(n_clusters=3, base_estimator=None, n_estimators=10, base_n_clusters=None, sample_fraction=1.0, feature_fraction=1.0, consensus='fcm', linkage='average', similarity='cosine', max_clusters=20, random_state=None, verbose=0)[source]#

Bases: ClusterMixin, BaseEstimator

Consensus of a library of soft clusterings (Punera and Ghosh, 2008).

A single run of an alternating-optimization clusterer depends on its initialization, its number of clusters and the particular sample it saw. An ensemble fits many such runs – different random starts, sub-samples, feature subsets or numbers of clusters – and combines their partitions into one consensus that is more stable and often more accurate than any member. Soft partitions carry more information than hard ones (how confidently an object was assigned), and the consensus functions of this class use them directly instead of hardening first.

Parameters:
n_clustersint or None, default=3

Number of consensus clusters. None picks it by the lifetime criterion of the co-association dendrogram (Fred and Jain, 2005).

base_estimatorestimator with predict_proba, default=None

Clusterer of the library; default FCM. It is cloned for every member and receives its own random_state.

n_estimatorsint, default=10

Size \(Q\) of the library.

base_n_clustersint, sequence of int or None, default=None

Number of clusters of the members: one value, or a sequence from which every member draws at random (a library over several \(c\) is the paper’s recipe for robustness). None uses n_clusters (which must then be given).

sample_fractionfloat, default=1.0

Share of the samples every member is fitted on (drawn without replacement); the member’s partition of all samples is obtained with its predict_proba.

feature_fractionfloat, default=1.0

Share of the features every member sees (at least one).

consensus{“fcm”, “spectral”, “hierarchical”, “smcla”, “itk”}, default=”fcm”

Consensus function: "fcm" clusters the rows of the co-association matrix with fuzzy c-means (a soft cluster-based similarity partitioning); "spectral" partitions the co-association graph by spectral clustering (sCSPA with a graph partitioner); "hierarchical" is evidence accumulation (average or single link on \(1-s_{kl}\)); "smcla" the soft meta-clustering algorithm; "itk" information-theoretic k-means on the concatenated memberships.

linkage{“average”, “single”, “complete”}, default=”average”

Linkage of the hierarchical consensus and of the lifetime criterion.

similarity{“cosine”, “product”}, default=”cosine”

Similarity of two membership vectors in the co-association matrix (coassociation_matrix()).

max_clustersint, default=20

Largest number of clusters the lifetime criterion considers.

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
base_estimators_list

The fitted members.

base_memberships_list of ndarray of shape (n_samples, c_q)

Partition of every member over all samples.

base_feature_subsets_list of ndarray

Feature indices every member used.

coassociation_ndarray of shape (n_samples, n_samples)

Soft co-association matrix \(s_{kl}\).

consensus_membership_ndarray of shape (n_samples, n_clusters_)

Consensus partition (membership_ is an alias). For the hard consensus functions (spectral, hierarchical, ITK) it is the fuzzy c-means membership (\(m=2\)) of every object’s co-association row to the mean rows of the consensus clusters.

labels_ndarray of shape (n_samples,)
n_clusters_int
lifetimes_ndarray of shape (max_clusters,)

Lifetime of \(k=1,\dots\) clusters in the dendrogram (computed when n_clusters is None or consensus="hierarchical").

linkage_ndarray

Linkage matrix of the co-association dendrogram (same condition).

meta_cluster_labels_ndarray

Meta-cluster of every library cluster (consensus="smcla").

consensus_centers_ndarray of shape (n_clusters_, n_samples)

Prototypes of the consensus clusters in the co-association space: the fuzzy c-means prototypes (consensus="fcm") or the mean rows of the clusters (hard consensus functions); not set for "smcla".

base_agreement_float

Mean fuzzy Rand index between the members and the consensus.

Notes

The co-association of two objects is the library average of the cosines (or inner products) of their membership vectors, \(s_{kl}=\frac1Q\sum_q\cos\big(\boldsymbol{\mu}^{(q)}_k,\boldsymbol{\mu}^{(q)}_l\big)\) (coassociation_matrix()). The members need not agree on the number or the labels of the clusters: only co-memberships are compared, which is why ensembles over several \(c\) work. New samples (predict_proba()) receive memberships from every member, their co-association with the training samples follows, and the consensus function’s own rule maps it to the consensus clusters.

References

[1]

K. Punera, J. Ghosh, “Consensus-based ensembles of soft clusterings”, Applied Artificial Intelligence 22(7–8), 780–810, 2008.

[2]

A. Strehl, J. Ghosh, “Cluster ensembles – a knowledge reuse framework for combining multiple partitions”, Journal of Machine Learning Research 3, 583–617, 2002.

[3]

A. L. N. Fred, A. K. Jain, “Combining multiple clusterings using evidence accumulation”, IEEE Transactions on Pattern Analysis and Machine Intelligence 27(6), 835–850, 2005.

Examples

>>> from fuzzyclust.ensemble import FuzzyClusterEnsemble
>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> X, y = make_fuzzy_blobs(random_state=0)
>>> ens = FuzzyClusterEnsemble(n_clusters=3, n_estimators=5, random_state=0).fit(X)
>>> ens.coassociation_.shape, ens.consensus_membership_.shape
((300, 300), (300, 3))
fit(X, y=None)[source]#

Fit the library and derive the consensus partition.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
Returns:
selfobject
predict(X)[source]#

Hard consensus labels of (new) samples.

predict_proba(X)[source]#

Consensus memberships of (new) samples.

Returns:
Undarray of shape (n_samples, n_clusters_)

Examples using fuzzyclust.ensemble.FuzzyClusterEnsemble#

Consensus of soft clusterings: a library beats a single run

Consensus of soft clusterings: a library beats a single run

The lifetime criterion of evidence accumulation

The lifetime criterion of evidence accumulation