fuzzyclust.coclustering.FCCM#
- class fuzzyclust.coclustering.FCCM(n_clusters=3, lambda_u=1.0, lambda_w=1.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
_BaseFuzzyCoClusteringFuzzy clustering for categorical multivariate data, FCCM (Oh, Honda, and Ichihashi, 2001).
A document–term matrix, a user–item purchase table or any other non-negative cooccurrence matrix \(\mathbf{R}\) has two sets of entities: objects (rows) and items (columns). Co-clustering looks for pairs of an object group and an item group that cooccur strongly – a topic together with its vocabulary. FCCM assigns a fuzzy membership to both the objects and the items of every co-cluster and maximizes the aggregation degree of the pairs, regularized by the entropies of both membership sets so that the solution stays fuzzy. Unlike k-means type clustering of the rows it needs no distance between sparse count vectors, and it returns, per cluster, which items characterize it.
- Parameters:
- n_clusters
int, default=3 Number of co-clusters \(c\).
- lambda_u
float, default=1.0 Entropy weight \(\lambda_u>0\) of the object memberships. It is measured in the units of a row’s aggregation \(a_{ik}=\sum_j w_{ij}r_{kj}\), which is a weighted mean of the row’s entries over the items of the co-cluster – so a value comparable to the typical entry of \(\mathbf{R}\) gives a moderately fuzzy partition, a much smaller value a nearly crisp one.
- lambda_w
float, default=1.0 Entropy weight \(\lambda_w>0\) of the item memberships, in the units of a column’s aggregation \(b_{ij}=\sum_k u_{ik}r_{kj}\), which is a weighted sum over the objects of the co-cluster and therefore grows with the number of objects.
- tol
float, default=1e-4 Termination tolerance on \(\max|\Delta u_{ik}|\).
- max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarrayofshape(n_objects,n_clusters), default=”random” - n_init
int, default=1 Random restarts; the run with the largest objective is kept.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- membership_
ndarrayofshape(n_objects,n_clusters) Object memberships \(u_{ik}\) (rows sum to one).
- item_membership_
ndarrayofshape(n_items,n_clusters) Item memberships \(w_{ij}\); every column (co-cluster) sums to one, so the entries are the share of the co-cluster’s item mass and are small when the vocabulary of a cluster is large.
- labels_
ndarrayofshape(n_objects,) Hard object labels.
- item_labels_
ndarrayofshape(n_items,) Co-cluster in which every item has its largest membership.
- aggregation_
float Final aggregation degree \(\sum_{ikj}u_{ik}w_{ij}r_{kj}\).
- objective_, objective_history_, n_iter_
Regularized objective (maximized) and its history.
- membership_
Notes
With object memberships \(u_{ik}\) (cluster \(i\), object \(k\)) and item memberships \(w_{ij}\) (item \(j\)), FCCM maximizes
\[J = \sum_{i=1}^{c}\sum_{k=1}^{N}\sum_{j=1}^{M} u_{ik}w_{ij}r_{kj} - \lambda_u\sum_{i=1}^{c}\sum_{k=1}^{N} u_{ik}\log u_{ik} - \lambda_w\sum_{i=1}^{c}\sum_{j=1}^{M} w_{ij}\log w_{ij}\]subject to \(\sum_{i}u_{ik}=1\) and \(\sum_{j}w_{ij}=1\). Without the entropy terms the maximum is crisp and degenerate (one cluster takes everything); the terms are the entropy regularization of Miyamoto and Mukaidono, and the necessary conditions are soft-max assignments
\[u_{ik} = \frac{\exp\big(\sum_j w_{ij}r_{kj}/\lambda_u\big)} {\sum_{l=1}^{c}\exp\big(\sum_j w_{lj}r_{kj}/\lambda_u\big)},\qquad w_{ij} = \frac{\exp\big(\sum_k u_{ik}r_{kj}/\lambda_w\big)} {\sum_{l=1}^{M}\exp\big(\sum_k u_{ik}r_{kl}/\lambda_w\big)},\]iterated alternately until the object memberships settle. New rows receive memberships through the first formula with the fitted item memberships (
predict_proba()).References
[1]C.-H. Oh, K. Honda, H. Ichihashi, “Fuzzy clustering for categorical multivariate data”, Proc. Joint 9th IFSA World Congress and 20th NAFIPS International Conference, 2154–2159, 2001.
[2]S. Miyamoto, M. Mukaidono, “Fuzzy c-means as a regularization and maximum entropy approach”, Proc. 7th IFSA World Congress, vol. 2, 86–92, 1997.
Examples
>>> from fuzzyclust.coclustering import FCCM, make_block_matrix >>> R, rows, cols = make_block_matrix(random_state=0) >>> fccm = FCCM(n_clusters=3, lambda_u=1.0, lambda_w=20.0, random_state=0).fit(R) >>> fccm.membership_.shape, fccm.item_membership_.shape ((120, 3), (60, 3))