Documentation
Classes
AgglomerativeClustering

AgglomerativeClustering

Agglomerative Clustering.

Recursively merges pair of clusters of sample data; uses linkage distance.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new AgglomerativeClustering(opts?: object): AgglomerativeClustering;

Parameters

NameTypeDescription
opts?object-
opts.affinity?stringThe metric to use when calculating distance between instances in a feature array. If metric is a string or callable, it must be one of the options allowed by sklearn.metrics.pairwise\_distances for its metric parameter. If linkage is “ward”, only “euclidean” is accepted. If “precomputed”, a distance matrix (instead of a similarity matrix) is needed as input for the fit method. Default Value 'euclidean'
opts.compute_distances?booleanComputes distances between clusters even if distance\_threshold is not used. This can be used to make dendrogram visualization, but introduces a computational and memory overhead. Default Value false
opts.compute_full_tree?boolean | "auto"Stop early the construction of the tree at n\_clusters. This is useful to decrease computation time if the number of clusters is not small compared to the number of samples. This option is useful only when specifying a connectivity matrix. Note also that when varying the number of clusters and using caching, it may be advantageous to compute the full tree. It must be true if distance\_threshold is not undefined. By default compute\_full\_tree is “auto”, which is equivalent to true when distance\_threshold is not undefined or that n\_clusters is inferior to the maximum between 100 or 0.02 \* n\_samples. Otherwise, “auto” is equivalent to false. Default Value 'auto'
opts.connectivity?ArrayLikeConnectivity matrix. Defines for each sample the neighboring samples following a given structure of the data. This can be a connectivity matrix itself or a callable that transforms the data into a connectivity matrix, such as derived from kneighbors\_graph. Default is undefined, i.e, the hierarchical clustering algorithm is unstructured.
opts.distance_threshold?numberThe linkage distance threshold at or above which clusters will not be merged. If not undefined, n\_clusters must be undefined and compute\_full\_tree must be true.
opts.linkage?"ward" | "complete" | "average" | "single"Which linkage criterion to use. The linkage criterion determines which distance to use between sets of observation. The algorithm will merge the pairs of cluster that minimize this criterion. Default Value 'ward'
opts.memory?stringUsed to cache the output of the computation of the tree. By default, no caching is done. If a string is given, it is the path to the caching directory.
opts.metric?stringMetric used to compute the linkage. Can be “euclidean”, “l1”, “l2”, “manhattan”, “cosine”, or “precomputed”. If set to undefined then “euclidean” is used. If linkage is “ward”, only “euclidean” is accepted. If “precomputed”, a distance matrix is needed as input for the fit method.
opts.n_clusters?numberThe number of clusters to find. It must be undefined if distance\_threshold is not undefined. Default Value 2

Returns

AgglomerativeClustering

Defined in: generated/cluster/AgglomerativeClustering.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/cluster/AgglomerativeClustering.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/cluster/AgglomerativeClustering.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/cluster/AgglomerativeClustering.ts:21 (opens in a new tab)

id

string

Defined in: generated/cluster/AgglomerativeClustering.ts:18 (opens in a new tab)

opts

any

Defined in: generated/cluster/AgglomerativeClustering.ts:19 (opens in a new tab)

Accessors

children_

The children of each non-leaf node. Values less than n\_samples correspond to leaves of the tree which are the original samples. A node i greater than or equal to n\_samples is a non-leaf node and has children children\_\[i \- n\_samples\]. Alternatively at the i-th iteration, children[i][0] and children[i][1] are merged to form node n\_samples + i.

Signature

children_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/cluster/AgglomerativeClustering.ts:414 (opens in a new tab)

distances_

Distances between nodes in the corresponding place in children\_. Only computed if distance\_threshold is used or compute\_distances is set to true.

Signature

distances_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/cluster/AgglomerativeClustering.ts:441 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/cluster/AgglomerativeClustering.ts:387 (opens in a new tab)

labels_

Cluster labels for each point.

Signature

labels_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/cluster/AgglomerativeClustering.ts:279 (opens in a new tab)

n_clusters_

The number of clusters found by the algorithm. If distance\_threshold=None, it will be equal to the given n\_clusters.

Signature

n_clusters_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/AgglomerativeClustering.ts:252 (opens in a new tab)

n_connected_components_

The estimated number of connected components in the graph.

Signature

n_connected_components_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/AgglomerativeClustering.ts:333 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/AgglomerativeClustering.ts:360 (opens in a new tab)

n_leaves_

Number of leaves in the hierarchical tree.

Signature

n_leaves_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/AgglomerativeClustering.ts:306 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/cluster/AgglomerativeClustering.ts:85 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/cluster/AgglomerativeClustering.ts:89 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/cluster/AgglomerativeClustering.ts:150 (opens in a new tab)

fit()

Fit the hierarchical clustering from features, or distance matrix.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining instances to cluster, or distances between instances if metric='precomputed'.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<any>

Defined in: generated/cluster/AgglomerativeClustering.ts:167 (opens in a new tab)

fit_predict()

Fit and return the result of each sample’s clustering assignment.

In addition to fitting, this method also return the result of the clustering assignment for each sample in the training set.

Signature

fit_predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Training instances to cluster, or distances between instances if affinity='precomputed'.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<ArrayLike>

Defined in: generated/cluster/AgglomerativeClustering.ts:209 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/cluster/AgglomerativeClustering.ts:98 (opens in a new tab)