fuzzyclust.collaborative.CollaborativeFCM#
- class fuzzyclust.collaborative.CollaborativeFCM(n_clusters=3, alpha=0.5, m=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseEstimatorHorizontal collaborative fuzzy clustering (Pedrycz, 2002).
The same \(N\) objects are described at \(P\) data sites by different sets of features – departments of a company, laboratories measuring different variables, sensors of different kinds – and the raw data must stay where they are (confidentiality, size, legacy formats). Each site runs its own fuzzy c-means; the sites then collaborate by exchanging only their partition matrices and re-run the clustering with an extra term that penalizes the difference between their own memberships and those of the other sites, weighted by a collaboration matrix \(\alpha[ii,jj]\). The structures found at the sites are pulled toward each other without any data leaving a site; how far they move tells how much the sites agree.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\), the same at every site (the sites must talk about the same clusters; after the independent phase the clusters of the sites are matched by the Hungarian algorithm on their membership overlap).
- alpha
floator array_likeofshape(n_sites,n_sites), default=0.5 Collaboration matrix \(\alpha[ii,jj]\ge0\), the weight site \(ii\) gives to the partition of site \(jj\); a scalar applies to all pairs.
0gives \(P\) independent FCM runs.- m
float, default=2.0 The paper’s updates are derived for \(m=2\); other values raise.
- tol
float, default=1e-4 Termination tolerance on \(\max|\Delta\mu|\) over all sites, used in both phases.
- max_iter
int, default=300 Maximal number of collaboration iterations (and of FCM iterations in the first phase).
- init{“random”, “kmeans++”}
orndarray, default=”random” Initialization of the independent FCM runs.
- n_init
int, default=1 Random restarts of the independent FCM runs (lowest \(J\) kept).
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- n_sites_
int - alpha_
ndarrayofshape(n_sites,n_sites) The collaboration matrix used (zero diagonal).
- memberships_
listofndarrayofshape(n_samples,n_clusters) Partition \(\mathbf{U}[ii]^T\) of every site after collaboration.
- cluster_centers_
listofndarrayofshape(n_clusters,n_features_ii) Prototypes of every site in its own feature space.
- labels_
listofndarrayofshape(n_samples,) - independent_memberships_, independent_centers_
list The results of the independent FCM runs (phase 1, clusters aligned).
- objective_
ndarrayofshape(n_sites,) Final collaborative objective \(Q[ii]\) of every site.
- objective_history_
ndarrayofshape(n_iter_,n_sites) - n_iter_
int Number of collaboration iterations.
- partition_distances_
ndarrayofshape(n_sites,n_sites) \(\frac1N\sum_{i,k}(\mu_{ik}[ii]-\mu_{ik}[jj])^2\) between the collaborative partitions;
independent_partition_distances_is the same for phase 1.- collaboration_change_
ndarrayofshape(n_sites,) Mean absolute membership change of every site from phase 1 to the collaborative result – how much the site gave in.
- consensus_membership_
ndarrayofshape(n_samples,n_clusters) Row-normalized mean of the site partitions after collaboration.
- n_sites_
Notes
Site \(ii\) minimizes, with its own squared distances \(D_{ik}^2[ii]\) to its prototypes,
\[Q[ii] = \sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^2[ii]\,D_{ik}^2[ii] + \sum_{jj\ne ii}\alpha[ii,jj]\sum_{i=1}^{c}\sum_{k=1}^{N} \big(\mu_{ik}[ii]-\mu_{ik}[jj]\big)^2 D_{ik}^2[ii] .\]The necessary conditions give, with the collaboration weight \(\bar\alpha[ii]=\sum_{jj\ne ii}\alpha[ii,jj]\) and the communicated memberships \(\varphi_{ik}[ii]=\sum_{jj\ne ii}\alpha[ii,jj]\mu_{ik}[jj]\big/\big(1+\bar\alpha[ii]\big)\),
\[\mu_{ik}[ii] = \varphi_{ik}[ii] + \frac{1-\sum_{l=1}^{c}\varphi_{lk}[ii]} {\sum_{l=1}^{c} D_{ik}^2[ii]/D_{lk}^2[ii]}, \qquad \mathbf{v}_i[ii] = \frac{\sum_k w_{ik}[ii]\,\mathbf{x}_k[ii]}{\sum_k w_{ik}[ii]}, \quad w_{ik}[ii] = \mu_{ik}^2[ii]+\sum_{jj\ne ii}\alpha[ii,jj]\big(\mu_{ik}[ii]-\mu_{ik}[jj]\big)^2 :\]the membership is a convex combination of the other sites’ memberships and the site’s own FCM membership, with weight \(\sum\alpha/(1+\sum\alpha)\) on the collaborators. The algorithm has two phases: independent FCM at every site, then synchronous collaboration iterations in which every site updates its prototypes and memberships from the partitions the other sites communicated in the previous round. New objects described at all sites receive memberships by iterating the membership formula with the fitted prototypes (
predict_proba()).References
[1]W. Pedrycz, “Collaborative fuzzy clustering”, Pattern Recognition Letters 23(14), 1675–1686, 2002.
Examples
>>> from fuzzyclust.collaborative import CollaborativeFCM, make_collaborative_sites >>> Xs, y = make_collaborative_sites(random_state=0) >>> cfcm = CollaborativeFCM(n_clusters=3, alpha=1.0, random_state=0).fit(Xs) >>> len(cfcm.memberships_), cfcm.memberships_[0].shape (2, (300, 3))
- fit(X, y=None)[source]#
Run the independent phase at every site, then the collaboration.
- Parameters:
- X
listofarray_like,eachofshape(n_samples,n_features_ii) The data sites; the rows of all arrays are the same objects.
- y
Ignored
- X
- Returns:
- self
object
- self
- predict_proba(X, max_iter=50)[source]#
Memberships of new objects at every site, with the fitted prototypes and collaboration.
- Parameters:
- X
listofarray_like The new objects described at every site (same order of sites as at fit time).
- max_iter
int, default=50 Iterations of the collaborative membership formula (starting from the independent FCM memberships of every site).
- X
- Returns:
- set_predict_proba_request(*, max_iter='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predict_probamethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredict_probaif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict_proba.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- site_agreement(index=<function fuzzy_rand_index>)[source]#
Pairwise agreement of the site partitions.
- Parameters:
- index
callable(), default=:func:fuzzyclust.validity.fuzzy_rand_index Comparison
index(U_a, U_b) -> floatof two membership matrices, e.g.fuzzy_adjusted_rand_index().
- index
- Returns:
- agreement
ndarrayofshape(n_sites,n_sites)
- agreement
Examples using fuzzyclust.collaborative.CollaborativeFCM#
Collaborative fuzzy clustering across three data sites