fuzzyclust.graph.MSTClustering#

class fuzzyclust.graph.MSTClustering(n_clusters=None, threshold=None, inconsistency=2.5, inconsistency_std=None, n_hops=2, criterion='hypervolume', min_gain=0.15, min_cluster_size=5, max_clusters=20, refine='gg', m=2.0, gamma=0.0, tol=0.0001, max_iter=100, backend='scipy', random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Hybrid clustering with a minimal spanning tree and Gath–Geva models.

A divisive graph-theoretic clusterer that combines the minimal spanning tree (MST) of the data with a fuzzy hypervolume splitting criterion and a final Gath–Geva (GG) refinement, following Vathy-Fogarassy, Feil and Abonyi (2005). The procedure has two phases (plus the refinement):

  1. Classical MST cutting (Step 0 of the paper). Edges are declared inconsistent and removed when they are longer than threshold times the mean edge length of the tree (Zahn’s global criterion, Criterion 1) or longer than inconsistency times the mean length – or more than inconsistency_std standard deviations above it – of the edges within n_hops tree steps of their end points (Zahn’s local criterion, Criterion 2). The connected components of the remaining forest are the coarse clusters: well separated groups and groups of clearly different density are found here, but a chain of points between two groups keeps them together, and a curved group stays one cluster.

  2. Volume-based binary splitting (Steps 1–3). The sub-cluster with the largest fuzzy hypervolume \(V_i=\sqrt{\det\mathbf{F}_i}\) is split by cutting every edge of its sub-tree in turn; each cut yields a candidate partition whose total hypervolume \(FHV=\sum_j V_j\) is evaluated, and the cut with the smallest \(FHV\) is kept if it lowers the volume of the split cluster by at least the relative gain min_gain (Criterion 3). This repeats depth-first until no cluster can be improved (or until n_clusters / max_clusters is reached). Elongated Gaussian groups are not split (halving them increases the total volume), whereas chains and curved groups are, so that every final cluster is well approximated by one ellipsoid.

  3. Refinement (Step 4). The crisp tree partition initializes a fuzzy clusterer (refine="gg" by default) with as many clusters as there are tree clusters. GG is very sensitive to its start and fails from an FCM start on such data; the tree partition is an excellent start and GG only polishes it, delivering memberships, covariance matrices and a parametric mixture-of-Gaussians description.

Parameters:
n_clustersint or None, default=None

Number of clusters. None lets the volume criterion decide. If given, the coarse phase may be undone edge by edge (shortest cut first) when it produces too many clusters, and the splitting phase continues (best available cut) until the requested number is reached.

thresholdfloat or None, default=None

Criterion 1: edges longer than threshold times the mean MST edge length are cut. None disables the criterion.

inconsistencyfloat or None, default=2.5

Criterion 2, ratio form: an edge is cut when it is at least inconsistency times longer than the mean of the other edges within n_hops steps of its end points (the factor \(f\) of Zahn and of the paper). None disables this form.

inconsistency_stdfloat or None, default=None

Criterion 2, deviation form (Zahn): an edge is cut when it exceeds the mean of the nearby edges by more than inconsistency_std standard deviations of their lengths. Either form flags an edge; None disables this form.

n_hopsint, default=2

Neighborhood depth (in tree steps) of Criterion 2. A deeper neighborhood averages over more edges and tolerates sparse spots inside a cluster; a shallow one reacts to every local gap.

criterion{“hypervolume”, “fukuyama_sugeno”}, default=”hypervolume”

Validity measure of the splitting phase: the total fuzzy hypervolume of Gath and Geva, or the (crisp) Fukuyama–Sugeno measure used by Varma and Simon, both evaluated on the crisp tree partition.

min_gainfloat, default=0.15

Minimum relative decrease of the volume criterion, \((V_i - V_a - V_b)/V_i\), for a split of cluster \(i\) into \(a\) and \(b\) to be accepted when n_clusters=None. Cutting a few tail points off a compact cluster always lowers the volume a little; the threshold separates such cosmetic cuts from real structure (chains, bends, merged groups).

min_cluster_sizeint, default=5

Cuts that would create a component with fewer samples are not applied (in either phase). Keeps single outliers from becoming clusters.

max_clustersint, default=20

Upper bound on the number of clusters when n_clusters=None: coarse cuts beyond it are undone (shortest first) and the splitting phase stops at it.

refine{“gg”, “fcm”} or None, default=”gg”

Fuzzy clusterer initialized with the tree partition. None keeps the crisp partition; memberships are then FCM-type memberships to the cluster means.

mfloat, default=2.0

Fuzziness exponent of the refinement.

gammafloat, default=0.0

Covariance regularization of the GG refinement, see GG.

tolfloat, default=1e-4
max_iterint, default=100

Termination of the refinement.

backend{“scipy”, “networkx”}, default=”scipy”

MST backend, see minimum_spanning_tree().

random_stateint, RandomState instance or None, default=None

Only used to break ties in the refinement (the tree is deterministic).

verboseint, default=0
Attributes:
n_clusters_int

Number of clusters found.

labels_ndarray of shape (n_samples,)

Final labels (argmax of membership_).

tree_labels_ndarray of shape (n_samples,)

Crisp labels of the tree partition before refinement.

membership_ndarray of shape (n_samples, n_clusters_)
cluster_centers_ndarray of shape (n_clusters_, n_features)
covariances_ndarray of shape (n_clusters_, n_features, n_features)

Fuzzy covariance matrices of the refined clusters (GG) or of the crisp tree clusters.

mst_edges_ndarray of shape (n_samples - 1, 2)

Edges of the minimal spanning tree (sorted by length).

mst_weights_ndarray of shape (n_samples - 1,)
cut_edges_ndarray of shape (n_cuts, 2)

End points of the removed edges.

cut_phases_ndarray of shape (n_cuts,)

0 for cuts of the threshold/inconsistency phase, 1 for volume-based splits.

cut_quality_ndarray of shape (n_cuts,)

Adequacy \(CP(e_{ab})=\sum_{k\in\{a,b\}}|\mu_{ik}-\mu_{jk}|\) of every cut in the final partition, where \(i,j\) are the clusters of the end points \(a,b\) (eq. 9 of the paper): values near \(2\) mean that the refinement confirmed the separation, values near \(0\) that the end points were re-united.

hypervolumes_ndarray of shape (n_clusters_,)

Fuzzy hypervolume of every tree cluster.

cluster_similarity_ndarray of shape (n_clusters_, n_clusters_)

Fuzzy similarity \(S_{ij}\) of the final clusters (fuzzy_cluster_similarity()), the basis of the paper’s dendrogram of clusters.

refiner_fitted GG or FCM, or None
distances_, objective_, objective_history_, n_iter_

Of the refinement (None/zeros when refine=None).

Notes

The fuzzy hypervolume of cluster \(j\) is

\[V_j = \sqrt{\det\mathbf{F}_j},\qquad \mathbf{F}_j = \frac{\sum_k\mu_{jk}^m(\mathbf{x}_k-\mathbf{v}_j) (\mathbf{x}_k-\mathbf{v}_j)^T}{\sum_k\mu_{jk}^m}, \qquad FHV=\sum_{j=1}^{c}V_j ,\]

evaluated here with the crisp memberships of the tree partition; the volume of the subtree on either side of every edge is obtained from subtree sums of \(\mathbf{x}_k\) and \(\mathbf{x}_k\mathbf{x}_k^T\), so that the statistics of all \(N_i-1\) candidate cuts of a sub-tree cost \(O(N_i n^2)\), plus two \(n\times n\) determinants (one for each side, \(O(n^3)\) each) per cut. The MST itself is built from the dense distance matrix, \(O(N^2)\) memory, which limits the method to a few thousand samples.

References

[1]

Á. Vathy-Fogarassy, B. Feil, J. Abonyi, “Minimal spanning tree based fuzzy clustering”, International Journal of Computer and Information Engineering 1(8), 2505–2510, 2007 (re-issue of the 2005 conference paper).

[2]

C. T. Zahn, “Graph-theoretical methods for detecting and describing gestalt clusters”, IEEE Trans. Computers C-20(1), 68–86, 1971.

[3]

I. Gath, A. B. Geva, “Unsupervised optimal fuzzy clustering”, IEEE Trans. Pattern Anal. Mach. Intell. 11(7), 773–781, 1989.

[4]

S. Varma, R. Simon, “Iterative class discovery and feature selection using minimal spanning trees”, BMC Bioinformatics 5, 126, 2004.

Examples

>>> from fuzzyclust.graph import MSTClustering
>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> X, y = make_fuzzy_blobs(n_clusters=3, random_state=0)
>>> mst = MSTClustering(random_state=0).fit(X)
>>> mst.n_clusters_, mst.mst_edges_.shape
(3, (299, 2))
fit(X, y=None)[source]#

Build the tree, cut it, split by volume and refine with GG.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
Returns:
selfobject

Examples using fuzzyclust.graph.MSTClustering#

Minimal spanning tree clustering: cutting, splitting, and Gath–Geva refinement

Minimal spanning tree clustering: cutting, splitting, and Gath–Geva refinement

Inconsistent edges: Zahn’s criteria and the neighborhood depth

Inconsistent edges: Zahn's criteria and the neighborhood depth

Number of clusters: volume-based validity and fuzzy cluster similarity

Number of clusters: volume-based validity and fuzzy cluster similarity