Scilab Website | Contribute with GitLab | Scilab Community | ATOMS toolboxes
Scilab Online Help
2027.0.0 - Русский


agglomerative

Perform agglomerative hierarchical clustering

Calling Sequence

labels = agglomerative(x, n_clusters)
labels = agglomerative(x, n_clusters, method)
labels = agglomerative(x, n_clusters, method, metric)

Arguments

x

A double observation matrix or a condensed distance vector or a linkage matrix returned by linkage.

If x is a matrix, each row represents one observation and each column represents one feature.

When x is a condensed distance vector, it contains the pairwise distances between observations.

When x is a linkage matrix Z, it must be a matrix with three columns produced by the linkage function.

n_clusters

A positive integer specifying the number of clusters to obtain.

n_clusters must be between 1 and n, the number of observations (number of rows of x).

method

Linkage method. The default value is "single".

  • "single": minimum distance linkage.

  • "complete": maximum distance linkage.

  • "average": average linkage unweighted by cluster sizes (UPGMA).

  • "weighted": weighted average linkage (WPGMA).

  • "centroid": centroid method (UPGMC).

  • "median": median method (WPGMC).

  • "ward": Ward minimum variance linkage.

This argument is ignored when x is already a linkage matrix.

metric

Metric used by pdist when x is a matrix. Default value: "euclidean".

A cell can be used to pass additional arguments to pdist, for example, to set the Minkowski metric.

The methods "centroid", "median" et "ward" require the Euclidean metric.

This argument is ignored when x is already a linkage matrix.

labels

A column vector containing the cluster label assigned to each observation.

Labels are integers ranging from 0 to n_clusters - 1.

Description

agglomerative performs agglomerative hierarchical clustering.

Agglomerative clustering is a bottom-up hierarchical clustering method. Initially, each observation belongs to its own cluster. At each iteration, the two closest active clusters are merged. The process continues until the requested number of clusters is reached.

The function can be used directly with an observation matrix, a condensed distance vector, or with a linkage matrix returned by linkage.

When a linkage matrix is provided, no new distances or merges are computed. The function uses the first n - n_clusters merges stored in the linkage hierarchy to reconstruct the requested partition.

Cluster labels are arbitrary identifiers. Two clustering results can represent the same partition even if their numerical labels are different.

For example: [0 0 1 1] and [1 1 0 0] represent the same clustering partition.

When n_clusters is equal to the number of observations, each observation receives a different label.

When n_clusters is equal to 1, all observations belong to the same cluster.

When a linkage matrix is supplied, the method and metric arguments are not used because the hierarchical clustering has already been computed.

Examples

data = [0.0   0.0
    0.2   0.1
    -0.1   0.2
    0.1  -0.2
    5.0   5.0
    5.2   5.1
    4.9   5.2
    5.1   4.8
    10.0   0.0
    10.2   0.1
    9.9  -0.2
    10.1   0.2];

labels = agglomerative(data, 3, "ward")
 
--> data = [0.0   0.0
  >                 0.2   0.1
  >                 -0.1   0.2
  >                 0.1  -0.2
  >                 5.0   5.0
  >                 5.2   5.1
  >                 4.9   5.2
  >                 5.1   4.8
  >                 10.0   0.0
  >                 10.2   0.1
  >                 9.9  -0.2
  >                 10.1   0.2];

--> labels = agglomerative(data, 3, "ward")

 labels = [12x1 double]

   1.
   1.
   1.
   1.
   2.
   2.
   2.
   2.
   0.
   0.
   0.
   0.
   

See Also

  • linkage — Agglomerative hierarchical clustering
  • pdist — Pairwise distances between observations
  • squareform — Conversion between a distance vector and a symmetric distance matrix

History

ВерсияОписание
2027.0.0 Function added.
Report an issue
<< Hypothesis Testing Statistics dbscan >>

Copyright (c) 2022-2026 (Dassault Systèmes S.E.)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 15 11:17:06 CEST 2026