fuzzyclust.cluster.CompatibleClusterMerging#

class fuzzyclust.cluster.CompatibleClusterMerging(base_estimator=None, start_n_clusters=8, min_n_clusters=1, criterion='geometric', parallel_threshold=0.95, hyperplane_threshold=0.5, distance_threshold=2.0, thin_threshold=0.2, similarity_threshold=0.2)[source]#

Bases: ClusterMixin, TransformerMixin, BaseEstimator

Compatible cluster merging: find the number of clusters by merging from a large start.

A base estimator (Gustafson–Kessel by default) is fitted with start_n_clusters clusters. The compatibility of every pair of clusters is evaluated, the most compatible pair above the thresholds is merged—their membership columns are added—and the base estimator is refitted from the merged partition with one cluster less. This repeats until no compatible pair remains or min_n_clusters is reached. The geometric criterion of Krishnapuram and Freg is meant for clusters that stand for lines, planes or local linear models: two thin clusters are compatible if their normals are parallel, their centers lie on the same hyperplane and are close. The similarity criterion (after Kaymak and Setnes) works for any shape: two clusters are compatible if their membership columns are similar as fuzzy sets.

Parameters:
base_estimatorfuzzyclust clusterer or None, default=None

Cloned and refitted at every step; None means GK(random_state=0). Its n_clusters and init are overridden. The geometric criterion needs covariances_ (FCM, GK, GG and most extensions provide it; otherwise the fuzzy covariances are computed from the partition).

start_n_clustersint, default=8

Deliberately large initial number of clusters \(c_{\max}\).

min_n_clustersint, default=1

Merging stops at this number of clusters at the latest.

criterion{“geometric”, “similarity”}, default=”geometric”

Compatibility criterion, see geometric_compatibility() and cluster_similarity().

parallel_thresholdfloat, default=0.95

\(\gamma_1\): minimal \(|\boldsymbol\phi_i\T\boldsymbol\phi_j|\) (geometric).

hyperplane_thresholdfloat, default=0.5

\(\gamma_2\): maximal offset of the centers from the common hyperplane, relative to the mean extent (geometric).

distance_thresholdfloat, default=2.0

\(\gamma_3\): maximal center distance relative to the sum of the extents (geometric).

thin_thresholdfloat, default=0.2

\(\gamma_4\): maximal \(\lambda_{\min}/\lambda_{\max}\) for a cluster to count as thin (geometric).

similarity_thresholdfloat, default=0.2

Minimal \(S_{ij}\) for a merge (similarity criterion). The similarity is evaluated on the partition rescaled to the reference exponent \(m=2\) (\(\mu_{ik}^{m-1}\), renormalized, see reference_fuzziness()), so that the threshold does not depend on the exponent of the base estimator. Two FCM clusters that share one Gaussian group have \(S_{ij}\approx0.35\) at \(m=2\) whatever \(c\), two separate groups well below \(0.2\).

Attributes:
estimator_fitted base estimator

The final model with n_clusters_ clusters.

n_clusters_int
cluster_centers_, membership_, labels_, distances_

Taken from estimator_.

merge_history_list of dict

One entry per merge with n_clusters (before the merge), pair (the merged clusters) and compatibility (degree or similarity).

compatibility_ndarray of shape (n_clusters_, n_clusters_)

Compatibility (or similarity) matrix of the final clusters; all entries are below the thresholds.

n_features_in_, feature_names_in_

Notes

Merging by adding membership columns and refitting with init set to the merged partition is the generic form of Kelly’s merging formulas for the center and covariance of the union: the first iteration of the refit computes exactly the membership-weighted center and covariance of the merged cluster. Because the number of clusters only decreases, the procedure costs at most \(c_{\max}-c^*\) refits, each started close to its solution, against \(c_{\max}-1\) refits from scratch for a validity scan.

References

[1]

R. Krishnapuram, C.-P. Freg, “Fitting an unknown number of lines and planes to image data through compatible cluster merging”, Pattern Recognition 25(4), 385–400, 1992.

[2]

U. Kaymak, M. Setnes, “Fuzzy clustering with volume prototypes and adaptive cluster merging”, IEEE Transactions on Fuzzy Systems 10(6), 705–712, 2002.

[3]

U. Kaymak, R. Babuška, “Compatible cluster merging for fuzzy modeling”, Proc. FUZZ-IEEE/IFES, Yokohama, 897–904, 1995.

Examples

>>> from fuzzyclust.cluster import CompatibleClusterMerging, GK
>>> from fuzzyclust.datasets import make_lines
>>> X, _ = make_lines(n_lines=3, random_state=0)
>>> ccm = CompatibleClusterMerging(GK(random_state=0), start_n_clusters=8).fit(X)
>>> int(ccm.n_clusters_)
3
fit(X, y=None)[source]#

Fit with start_n_clusters clusters and merge compatible pairs.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
Returns:
selfobject
fit_transform(X, y=None, **fit_params)[source]#

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
Xarray_like of shape (n_samples, n_features)

Input samples.

yarray_like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

predict(X)[source]#

Hard labels of (new) samples.

predict_proba(X)[source]#

Memberships of (new) samples in the final clusters.

score(X, y=None)[source]#

Score of the final estimator (negative objective).

transform(X)[source]#

Distances of samples to the final prototypes, shape (n_samples, n_clusters_).

Examples using fuzzyclust.cluster.CompatibleClusterMerging#

Three routes to the number of clusters: merging, validity scan, and stability

Three routes to the number of clusters: merging, validity scan, and stability