graphclust.cluster.MSTClustering#
- class graphclust.cluster.MSTClustering(n_clusters=None, *, lambda_=2.0, criterion='both', depth=2, min_cluster_size=1)[source]#
Bases:
ClusterMixin,BaseEstimatorMinimal 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 thanlambda_times the mean length of all tree edges;criterion="local"(second criterion): the edge is longer thanlambda_times the mean length of the tree edges withindepthsteps of its end points, which also separates clusters of different density;criterion="both": either of the two.
If
n_clustersis given, removal stops when that many components exist; withcriterion=Nonethen_clusters - 1longest edges are removed, which reproduces single-linkage clustering.- Attributes:
- mst_
sparsematrix,thetree;removed_edges_listofremoved(i,j); - labels_
connectedcomponentsaftertheremoval.
- mst_
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