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,BaseEstimatorCompatible 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_clustersclusters. 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 ormin_n_clustersis 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_estimator
fuzzyclustclustererorNone, default=None Cloned and refitted at every step;
NonemeansGK(random_state=0). Itsn_clustersandinitare overridden. The geometric criterion needscovariances_(FCM, GK, GG and most extensions provide it; otherwise the fuzzy covariances are computed from the partition).- start_n_clusters
int, default=8 Deliberately large initial number of clusters \(c_{\max}\).
- min_n_clusters
int, default=1 Merging stops at this number of clusters at the latest.
- criterion{“geometric”, “similarity”}, default=”geometric”
Compatibility criterion, see
geometric_compatibility()andcluster_similarity().- parallel_threshold
float, default=0.95 \(\gamma_1\): minimal \(|\boldsymbol\phi_i\T\boldsymbol\phi_j|\) (geometric).
- hyperplane_threshold
float, default=0.5 \(\gamma_2\): maximal offset of the centers from the common hyperplane, relative to the mean extent (geometric).
- distance_threshold
float, default=2.0 \(\gamma_3\): maximal center distance relative to the sum of the extents (geometric).
- thin_threshold
float, default=0.2 \(\gamma_4\): maximal \(\lambda_{\min}/\lambda_{\max}\) for a cluster to count as thin (geometric).
- similarity_threshold
float, 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\).
- base_estimator
- Attributes:
- estimator_
fittedbaseestimator The final model with
n_clusters_clusters.- n_clusters_
int - cluster_centers_, membership_, labels_, distances_
Taken from
estimator_.- merge_history_
listofdict One entry per merge with
n_clusters(before the merge),pair(the merged clusters) andcompatibility(degree or similarity).- compatibility_
ndarrayofshape(n_clusters_,n_clusters_) Compatibility (or similarity) matrix of the final clusters; all entries are below the thresholds.
- n_features_in_, feature_names_in_
- estimator_
Notes
Merging by adding membership columns and refitting with
initset 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_clustersclusters and merge compatible pairs.- Parameters:
- Xarray_like
ofshape(n_samples,n_features) - y
Ignored
- Xarray_like
- Returns:
- self
object
- self
- 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
ofshape(n_samples,n_features) Input samples.
- yarray_like
ofshape(n_samples,)or(n_samples,n_outputs), default=None Target values (None for unsupervised transformations).
- **fit_params
dict Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.
- Xarray_like
- Returns:
Examples using fuzzyclust.cluster.CompatibleClusterMerging#
Three routes to the number of clusters: merging, validity scan, and stability