FUNCTION REFERENCE

linkage

Agglomerative hierarchical clustering.

Agglomerative hierarchical clustering.

Syntax

Z = linkage(X,method,metric)

X can be an observation matrix (including one column) or a condensed pdist row vector. Default method is 'single'; also 'complete', 'average', 'weighted', 'centroid', 'median', 'ward'. Default metric is Euclidean; centroid, median and ward require Euclidean distances. Condensed input for those methods is checked using the positive semidefiniteness of its centered squared-distance matrix. Each Z row stores two cluster identifiers and the merge distance; original observations are 1..m, new nodes m+1..2m-1 in merge order. Exact minimum-distance ties choose the lexicographically smallest pair of active cluster identifiers, and children are ascending.

Example

z = linkage([1 3 2],'single');   % [1 2 1;3 4 2]

Differences from MATLAB: Tied merge order is a deterministic MatRust choice; it can differ from SciPy. Row vectors denote condensed distances; column vectors denote one-variable observations. NaN/infinite distances are rejected. Uses a bounded pair heap and cooperative cancellation. The Euclidean check tolerates rounding-sized negative eigenvalues.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.