Loading [MathJax]/extensions/tex2jax.js
scipy 1.10.1 Pypi GitHub Homepage
Other Docs

ParametersReturns
cut_tree(Z, n_clusters=None, height=None)

Parameters

Z : scipy.cluster.linkage array

The linkage matrix.

n_clusters : array_like, optional

Number of clusters in the tree at the cut point.

height : array_like, optional

The height at which to cut the tree. Only possible for ultrametric trees.

Returns

cutree : array

An array indicating group membership at each agglomeration step. I.e., for a full cut tree, in the first column each data point is in its own cluster. At the next step, two nodes are merged. Finally, all singleton and non-singleton clusters are in one group. If n_clusters or height are given, the columns correspond to the columns of n_clusters or height.

Given a linkage matrix Z, return the cut tree.

Examples

from scipy import cluster
import numpy as np
from numpy.random import default_rng
rng = default_rng()
X = rng.random((50, 4))
Z = cluster.hierarchy.ward(X)
cutree = cluster.hierarchy.cut_tree(Z, n_clusters=[5, 10])
cutree[:10]
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/cluster/hierarchy.py#1317
type: <class 'function'>
Commit: