Clusterer
TimeSeriesKMedoids
Time series K-medoids implementation.
Quickstart
python
from sktime.clustering.k_medoids import TimeSeriesKMedoids
estimator = TimeSeriesKMedoids(n_clusters: int=8, init_algorithm: str | Callable='random', metric: str | Callable='dtw', n_init: int=10, max_iter: int=300, tol: float=1e-06, verbose: bool=False, random_state: int | RandomState=None, distance_params: dict=None)Parameters(9)
- n_clusters: int, defaults = 8
- The number of clusters to form as well as the number of centroids to generate.
- init_algorithm: str, np.ndarray (3d array of shape (n_clusters, n_dimensions,
series_length)), defaults = ‘forgy’ Method for initializing cluster centers or an array of initial cluster centers. If string, any of the following strings are valid:
[‘kmeans++’, ‘random’, ‘forgy’].
If 3D np.ndarray, initializes cluster centers with the provided array. The arraymust have shape (n_clusters, n_dimensions, series_length) and the number of clusters in the array must be the same as what is provided to the n_clusters argument.
- metric: str or Callable, defaults = ‘dtw’
- Distance metric to compute similarity between time series. Any of the following are valid: [‘dtw’, ‘euclidean’, ‘erp’, ‘edr’, ‘lcss’, ‘squared’, ‘ddtw’, ‘wdtw’, ‘wddtw’]
- n_init: int, defaults = 10
- Number of times the k-means algorithm will be run with different centroid seeds. The final result will be the best output of n_init consecutive runs in terms of inertia.
- max_iter: int, defaults = 30
- Maximum number of iterations of the k-means algorithm for a single run.
- tol: float, defaults = 1e-6
- Relative tolerance with regards to Frobenius norm of the difference in the cluster centers of two consecutive iterations to declare convergence.
- verbose: bool, defaults = False
- Verbosity mode.
- random_state: int or np.random.RandomState instance or None, defaults = None
- Determines random number generation for centroid initialization.
- distance_params: dict, defaults = None
- Dictionary containing kwargs for the distance metric being used.
Examples
>>> from sktime.datasets import load_arrow_head
>>> from sktime.clustering.k_medoids import TimeSeriesKMedoids
>>> X_train, y_train = load_arrow_head (split = "train")
>>> X_test, y_test = load_arrow_head (split = "test")
>>> clusterer = TimeSeriesKMedoids (n_clusters = 3)
>>> clusterer. fit (X_train) TimeSeriesKMedoids(n_clusters=3)
>>> y_pred = clusterer. predict (X_test)