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: BaseEstimator

Horizontal 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_clustersint, 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).

alphafloat or array_like of shape (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. 0 gives \(P\) independent FCM runs.

mfloat, default=2.0

The paper’s updates are derived for \(m=2\); other values raise.

tolfloat, default=1e-4

Termination tolerance on \(\max|\Delta\mu|\) over all sites, used in both phases.

max_iterint, default=300

Maximal number of collaboration iterations (and of FCM iterations in the first phase).

init{“random”, “kmeans++”} or ndarray, default=”random”

Initialization of the independent FCM runs.

n_initint, default=1

Random restarts of the independent FCM runs (lowest \(J\) kept).

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
n_sites_int
alpha_ndarray of shape (n_sites, n_sites)

The collaboration matrix used (zero diagonal).

memberships_list of ndarray of shape (n_samples, n_clusters)

Partition \(\mathbf{U}[ii]^T\) of every site after collaboration.

cluster_centers_list of ndarray of shape (n_clusters, n_features_ii)

Prototypes of every site in its own feature space.

labels_list of ndarray of shape (n_samples,)
independent_memberships_, independent_centers_list

The results of the independent FCM runs (phase 1, clusters aligned).

objective_ndarray of shape (n_sites,)

Final collaborative objective \(Q[ii]\) of every site.

objective_history_ndarray of shape (n_iter_, n_sites)
n_iter_int

Number of collaboration iterations.

partition_distances_ndarray of shape (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_ndarray of shape (n_sites,)

Mean absolute membership change of every site from phase 1 to the collaborative result – how much the site gave in.

consensus_membership_ndarray of shape (n_samples, n_clusters)

Row-normalized mean of the site partitions after collaboration.

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:
Xlist of array_like, each of shape (n_samples, n_features_ii)

The data sites; the rows of all arrays are the same objects.

yIgnored
Returns:
selfobject
predict(X)[source]#

Hard labels of new objects at every site.

predict_proba(X, max_iter=50)[source]#

Memberships of new objects at every site, with the fitted prototypes and collaboration.

Parameters:
Xlist of array_like

The new objects described at every site (same order of sites as at fit time).

max_iterint, default=50

Iterations of the collaborative membership formula (starting from the independent FCM memberships of every site).

Returns:
Uslist of ndarray of shape (n_samples, n_clusters)
set_predict_proba_request(*, max_iter='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the predict_proba method.

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 (see sklearn.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 to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_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.

Parameters:
max_iterstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for max_iter parameter in predict_proba.

Returns:
selfobject

The updated object.

site_agreement(index=<function fuzzy_rand_index>)[source]#

Pairwise agreement of the site partitions.

Parameters:
indexcallable(), default=:func:fuzzyclust.validity.fuzzy_rand_index

Comparison index(U_a, U_b) -> float of two membership matrices, e.g. fuzzy_adjusted_rand_index().

Returns:
agreementndarray of shape (n_sites, n_sites)
transform(X)[source]#

Distances of new objects to the prototypes of every site.

Examples using fuzzyclust.collaborative.CollaborativeFCM#

Collaborative fuzzy clustering across three data sites

Collaborative fuzzy clustering across three data sites