graphclust.cluster.MSTClustering#

class graphclust.cluster.MSTClustering(n_clusters=None, *, lambda_=2.0, criterion='both', depth=2, min_cluster_size=1)[source]#

Bases: ClusterMixin, BaseEstimator

Minimal spanning tree clustering with Zahn’s inconsistent-edge criteria.

The Euclidean MST of the data is built and edges are removed in order of decreasing length while they are inconsistent:

  • criterion="global" (Zahn’s first criterion): the edge is longer than lambda_ times the mean length of all tree edges;

  • criterion="local" (second criterion): the edge is longer than lambda_ times the mean length of the tree edges within depth steps of its end points, which also separates clusters of different density;

  • criterion="both": either of the two.

If n_clusters is given, removal stops when that many components exist; with criterion=None the n_clusters - 1 longest edges are removed, which reproduces single-linkage clustering.

Attributes:
mst_sparse matrix, the tree; removed_edges_list of removed (i, j);
labels_connected components after the removal.

Examples

>>> import numpy as np
>>> X = np.r_[np.random.default_rng(0).normal(0, .1, (30, 2)), np.random.default_rng(1).normal(3, .1, (30, 2))]
>>> int(MSTClustering(lambda_=3, criterion="global").fit(X).labels_.max())
1