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,BaseEstimatorConsensus 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_clusters
intorNone, default=3 Number of consensus clusters.
Nonepicks it by the lifetime criterion of the co-association dendrogram (Fred and Jain, 2005).- base_estimator
estimatorwithpredict_proba, default=None Clusterer of the library; default
FCM. It is cloned for every member and receives its ownrandom_state.- n_estimators
int, default=10 Size \(Q\) of the library.
- base_n_clusters
int, sequenceofintorNone, 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).
Noneusesn_clusters(which must then be given).- sample_fraction
float, 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_fraction
float, 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_clusters
int, default=20 Largest number of clusters the lifetime criterion considers.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- base_estimators_
list The fitted members.
- base_memberships_
listofndarrayofshape(n_samples,c_q) Partition of every member over all samples.
- base_feature_subsets_
listofndarray Feature indices every member used.
- coassociation_
ndarrayofshape(n_samples,n_samples) Soft co-association matrix \(s_{kl}\).
- consensus_membership_
ndarrayofshape(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_
ndarrayofshape(n_samples,) - n_clusters_
int - lifetimes_
ndarrayofshape(max_clusters,) Lifetime of \(k=1,\dots\) clusters in the dendrogram (computed when
n_clustersisNoneorconsensus="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_
ndarrayofshape(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.
- base_estimators_
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
ofshape(n_samples,n_features) - y
Ignored
- Xarray_like
- Returns:
- self
object
- self
Examples using fuzzyclust.ensemble.FuzzyClusterEnsemble#
Consensus of soft clusterings: a library beats a single run