milia.cluster.models.kshape#

k-Shape: shape-based clustering with cross-correlation distance (tslearn).

Classes

KShape([n_clusters, n_init, max_iter, ...])

k-Shape (Paparrizos and Gravano, 2015); rows are z-normalised before clustering.

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

Validated hyperparameters of the k-Shape clusterer.

class milia.cluster.models.kshape.KShape(n_clusters=3, n_init=1, max_iter=100, random_state=0)#

Bases: BaseClusterer

k-Shape (Paparrizos and Gravano, 2015); rows are z-normalised before clustering.

Parameters:
  • n_clusters (int) – Number of clusters.

  • n_init (int) – Restarts.

  • max_iter (int) – Iterations per run.

  • random_state (int | None) – Seed.

Examples

>>> import numpy as np
>>> t = np.linspace(0, 2 * np.pi, 24)
>>> X = np.vstack([np.sin(t + s) for s in (0.0, 0.1, 0.2)] + [np.cos(3 * t + s) for s in (0.0, 0.1, 0.2)])
>>> KShape(n_clusters=2).fit(X).labels_.tolist()
[1, 1, 1, 0, 0, 0]
class milia.cluster.models.kshape.KShapeConfig(*, name='kshape', kind='clusterer', space=SearchSpace(n_clusters=(2, 12)), n_clusters=3, n_init=1, max_iter=100, random_state=0)#

Bases: BaseModelConfig

Validated hyperparameters of the k-Shape clusterer.

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

Examples

>>> KShapeConfig().name
'kshape'