milia.cluster.models.agglomerative#

Agglomerative (hierarchical) clustering.

Classes

Agglomerative([n_clusters, linkage, metric])

Bottom-up hierarchical clustering.

AgglomerativeConfig(*[, name, kind, space, ...])

Validated hyperparameters of the agglomerative clusterer.

class milia.cluster.models.agglomerative.Agglomerative(n_clusters=3, linkage='ward', metric='euclidean')#

Bases: BaseClusterer

Bottom-up hierarchical clustering.

With metric="precomputed" it clusters a square distance matrix directly, as the CROCS representation needs (linkage must then not be "ward").

Parameters:
  • n_clusters (int) – Number of clusters to cut the tree at.

  • linkage (str) – "ward", "average", "complete" or "single".

  • metric (str) – Distance metric, or "precomputed".

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> X = np.repeat(np.array([[0.0, 0.0], [6.0, 6.0], [0.0, 6.0]]), 20, axis=0) + rng.normal(
...     scale=0.4, size=(60, 2)
... )
>>> Agglomerative(n_clusters=3).fit(X).n_clusters_
3
class milia.cluster.models.agglomerative.AgglomerativeConfig(*, name='agglomerative', kind='clusterer', space=SearchSpace(n_clusters=(2, 12), linkage=['ward', 'average']), n_clusters=3, linkage='ward', metric='euclidean')#

Bases: BaseModelConfig

Validated hyperparameters of the agglomerative clusterer.

Fields mirror Agglomerative’s constructor; space is the default Optuna search space. Build the clusterer with make("clusterer", "agglomerative", ...) or Agglomerative(**config.params()).

Examples

>>> AgglomerativeConfig().name
'agglomerative'