diff --git a/aeon/clustering/__init__.py b/aeon/clustering/__init__.py index 084778aed6..2eec5142cf 100644 --- a/aeon/clustering/__init__.py +++ b/aeon/clustering/__init__.py @@ -7,7 +7,6 @@ "TimeSeriesCLARANS", "TimeSeriesKMeans", "TimeSeriesKShape", - "TimeSeriesKShapes", "TimeSeriesKernelKMeans", "ElasticSOM", "KSpectralCentroid", @@ -21,7 +20,6 @@ from aeon.clustering._k_medoids import TimeSeriesKMedoids from aeon.clustering._k_sc import KSpectralCentroid from aeon.clustering._k_shape import TimeSeriesKShape -from aeon.clustering._k_shapes import TimeSeriesKShapes from aeon.clustering._kernel_k_means import TimeSeriesKernelKMeans from aeon.clustering.base import BaseClusterer from aeon.clustering.dummy import DummyClusterer diff --git a/aeon/clustering/_k_means.py b/aeon/clustering/_k_means.py index 550d38944e..97806915bc 100644 --- a/aeon/clustering/_k_means.py +++ b/aeon/clustering/_k_means.py @@ -169,20 +169,8 @@ def __init__( averaging_method: Union[str, Callable[[np.ndarray], np.ndarray]] = "ba", distance_params: Optional[dict] = None, average_params: Optional[dict] = None, - init_algorithm: Optional[Union[str, np.ndarray]] = None, ): self.init = init - self.init_algorithm = init_algorithm - if init_algorithm is not None: - import warnings - - warnings.warn( - "The 'init_algorithm' parameter is deprecated and will be " - "removed in a future. Version Use 'init' instead.", - DeprecationWarning, - stacklevel=2, - ) - self.init = self.init_algorithm self.distance = distance self.n_init = n_init self.max_iter = max_iter diff --git a/aeon/clustering/_k_shapes.py b/aeon/clustering/_k_shapes.py deleted file mode 100644 index cdad58032a..0000000000 --- a/aeon/clustering/_k_shapes.py +++ /dev/null @@ -1,185 +0,0 @@ -"""Time series kshapes.""" - -from typing import Optional, Union - -import numpy as np -from deprecated.sphinx import deprecated -from numpy.random import RandomState - -from aeon.clustering.base import BaseClusterer - - -# TODO: remove in v1.0.0 -@deprecated( - version="1.0.0", - reason="TimeSeriesKShapes class has been renamed to TimeSeriesKShape. " - "The TimeSeriesKShapes version will be removed in version 1.0.0.", - category=FutureWarning, -) -class TimeSeriesKShapes(BaseClusterer): - """Kshape algorithm: wrapper of the ``tslearn`` implementation. - - Parameters - ---------- - n_clusters: int, default=8 - The number of clusters to form as well as the number of - centroids to generate. - init_algorithm: str or np.ndarray, default='random' - Method for initializing cluster centres. Any of the following are valid: - ['random']. Or a np.ndarray of shape (n_clusters, n_channels, n_timepoints) - and gives the initial cluster centres. - n_init: int, default=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, default=30 - Maximum number of iterations of the k-means algorithm for a single - run. - tol: float, default=1e-4 - Relative tolerance with regards to Frobenius norm of the difference - in the cluster centres of two consecutive iterations to declare - convergence. - verbose: bool, default=False - Verbosity mode. - random_state: int or np.random.RandomState instance or None, default=None - Determines random number generation for centroid initialization. - - Attributes - ---------- - labels_: np.ndarray (1d array of shape (n_cases,)) - Labels that is the index each time series belongs to. - inertia_: float - Sum of squared distances of samples to their closest cluster centre, weighted by - the sample weights if provided. - n_iter_: int - Number of iterations run. - - Examples - -------- - >>> from aeon.clustering import TimeSeriesKShapes - >>> from aeon.datasets import load_basic_motions - >>> # Load data - >>> X_train, y_train = load_basic_motions(split="TRAIN")[0:10] - >>> X_test, y_test = load_basic_motions(split="TEST")[0:10] - >>> # Example of KShapes clustering - >>> ks = TimeSeriesKShapes(n_clusters=3, random_state=1) # doctest: +SKIP - >>> ks.fit(X_train) # doctest: +SKIP - TimeSeriesKShapes(n_clusters=3, random_state=1) - >>> preds = ks.predict(X_test) # doctest: +SKIP - """ - - _tags = { - "capability:multivariate": True, - "python_dependencies": "tslearn", - "algorithm_type": "distance", - } - - def __init__( - self, - n_clusters: int = 8, - init_algorithm: Union[str, np.ndarray] = "random", - n_init: int = 10, - max_iter: int = 300, - tol: float = 1e-4, - verbose: bool = False, - random_state: Optional[Union[int, RandomState]] = None, - ): - self.init_algorithm = init_algorithm - self.n_init = n_init - self.max_iter = max_iter - self.tol = tol - self.verbose = verbose - self.random_state = random_state - - self.cluster_centers_ = None - self.labels_ = None - self.inertia_ = None - self.n_iter_ = 0 - - self._tslearn_k_shapes = None - - super().__init__(n_clusters=n_clusters) - - def _fit(self, X, y=None): - """Fit time series clusterer to training data. - - Parameters - ---------- - X: np.ndarray, of shape (n_cases, n_channels, n_timepoints) or - (n_cases, n_timepoints) - A collection of time series instances. - y: ignored, exists for API consistency reasons. - - Returns - ------- - self: - Fitted estimator. - """ - from tslearn.clustering import KShape - - self._tslearn_k_shapes = KShape( - n_clusters=self.n_clusters, - max_iter=self.max_iter, - tol=self.tol, - random_state=self.random_state, - n_init=self.n_init, - verbose=self.verbose, - init=self.init_algorithm, - ) - - _X = X.swapaxes(1, 2) - - self._tslearn_k_shapes.fit(_X) - self._cluster_centers = self._tslearn_k_shapes.cluster_centers_ - self.labels_ = self._tslearn_k_shapes.labels_ - self.inertia_ = self._tslearn_k_shapes.inertia_ - self.n_iter_ = self._tslearn_k_shapes.n_iter_ - - def _predict(self, X, y=None) -> np.ndarray: - """Predict the closest cluster each sample in X belongs to. - - Parameters - ---------- - X: np.ndarray, of shape (n_cases, n_channels, n_timepoints) or - (n_cases, n_timepoints) - A collection of time series instances. - y: ignored, exists for API consistency reasons. - - Returns - ------- - np.ndarray (1d array of shape (n_cases,)) - Index of the cluster each time series in X belongs to. - """ - _X = X.swapaxes(1, 2) - return self._tslearn_k_shapes.predict(_X) - - @classmethod - def _get_test_params(cls, parameter_set="default"): - """Return testing parameter settings for the estimator. - - Parameters - ---------- - parameter_set : str, default="default" - Name of the set of test parameters to return, for use in tests. If no - special parameters are defined for a value, will return `"default"` set. - - - Returns - ------- - params : dict or list of dict, default={} - Parameters to create testing instances of the class - Each dict are parameters to construct an "interesting" test instance, i.e., - `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. - """ - return { - "n_clusters": 2, - "init_algorithm": "random", - "n_init": 1, - "max_iter": 1, - "tol": 1e-4, - "verbose": False, - "random_state": 1, - } - - def _score(self, X, y=None): - return np.abs(self.inertia_) diff --git a/aeon/clustering/deep_learning/_ae_bgru.py b/aeon/clustering/deep_learning/_ae_bgru.py index 9b7df32716..e400bdaa05 100644 --- a/aeon/clustering/deep_learning/_ae_bgru.py +++ b/aeon/clustering/deep_learning/_ae_bgru.py @@ -22,8 +22,6 @@ class AEBiGRUClusterer(BaseDeepClusterer): ---------- n_clusters : int, default=None Number of clusters for the deep learnign model. - clustering_algorithm : str, default="deprecated" - Use 'estimator' parameter instead. clustering_params : dict, default=None Use 'estimator' parameter instead. estimator : aeon clusterer, default=None @@ -100,7 +98,6 @@ class AEBiGRUClusterer(BaseDeepClusterer): def __init__( self, n_clusters=None, - clustering_algorithm="deprecated", estimator=None, clustering_params=None, latent_space_dim=128, diff --git a/aeon/clustering/deep_learning/_ae_fcn.py b/aeon/clustering/deep_learning/_ae_fcn.py index 70b55bb420..15df93af8e 100644 --- a/aeon/clustering/deep_learning/_ae_fcn.py +++ b/aeon/clustering/deep_learning/_ae_fcn.py @@ -27,8 +27,6 @@ class AEFCNClusterer(BaseDeepClusterer): An aeon estimator to be built using the transformed data. Defaults to aeon TimeSeriesKMeans() with euclidean distance and mean averaging method and n_clusters set to 2. - clustering_algorithm : str, default="deprecated" - Please use 'estimator' parameter. clustering_params : dict, default=None Please use 'estimator' parameter. latent_space_dim : int, default=128 @@ -124,7 +122,6 @@ def __init__( self, n_clusters=None, estimator=None, - clustering_algorithm="deprecated", clustering_params=None, latent_space_dim=128, temporal_latent_space=False, @@ -177,7 +174,6 @@ def __init__( super().__init__( estimator=estimator, n_clusters=n_clusters, - clustering_algorithm=clustering_algorithm, clustering_params=clustering_params, batch_size=batch_size, last_file_name=last_file_name, diff --git a/aeon/clustering/deep_learning/_ae_resnet.py b/aeon/clustering/deep_learning/_ae_resnet.py index d9f3ebd52e..2a7f308d4a 100644 --- a/aeon/clustering/deep_learning/_ae_resnet.py +++ b/aeon/clustering/deep_learning/_ae_resnet.py @@ -30,8 +30,6 @@ class AEResNetClusterer(BaseDeepClusterer): An aeon estimator to be built using the transformed data. Defaults to aeon TimeSeriesKMeans() with euclidean distance and mean averaging method and n_clusters set to 2. - clustering_algorithm : str, default="deprecated" - Please use 'estimator' parameter. clustering_params : dict, default=None Please use 'estimator' parameter. latent_space_dim : int, default=128 @@ -134,7 +132,6 @@ def __init__( n_clusters=None, estimator=None, n_residual_blocks=3, - clustering_algorithm="deprecated", clustering_params=None, n_conv_per_residual_block=3, n_filters=None, @@ -188,7 +185,6 @@ def __init__( super().__init__( estimator=estimator, n_clusters=n_clusters, - clustering_algorithm=clustering_algorithm, clustering_params=clustering_params, batch_size=batch_size, last_file_name=last_file_name, diff --git a/aeon/clustering/deep_learning/base.py b/aeon/clustering/deep_learning/base.py index dc84d7c187..ba4d4ac00a 100644 --- a/aeon/clustering/deep_learning/base.py +++ b/aeon/clustering/deep_learning/base.py @@ -19,8 +19,6 @@ class BaseDeepClusterer(BaseClusterer): An aeon estimator to be built using the transformed data. Defaults to aeon TimeSeriesKMeans() with euclidean distance and mean averaging method and n_clusters set to 2. - clustering_algorithm : str, default="deprecated" - Please use 'estimator' parameter. clustering_params : dict, default=None Please use 'estimator' parameter. batch_size : int, default = 40 @@ -44,14 +42,12 @@ def __init__( self, n_clusters=None, estimator=None, - clustering_algorithm="deprecated", clustering_params=None, batch_size=32, last_file_name="last_file", ): self.estimator = estimator self.n_clusters = n_clusters - self.clustering_algorithm = clustering_algorithm self.clustering_params = clustering_params self.batch_size = batch_size self.last_file_name = last_file_name @@ -109,8 +105,6 @@ def _fit_clustering(self, X): X : np.ndarray, shape=(n_cases, n_timepoints, n_channels) The input time series. """ - import warnings - self._estimator = ( TimeSeriesKMeans( n_clusters=2, distance="euclidean", averaging_method="mean" @@ -120,22 +114,6 @@ def _fit_clustering(self, X): ) # to be removed in 1.0.0 - if ( - self.clustering_algorithm != "deprecated" - or self.clustering_params is not None - or self.n_clusters is not None - ): - warnings.warn( - "The 'n_clusters' 'clustering_algorithm' and " - "'clustering_params' parameters " - "will be removed in v1.0.0. " - "Their usage will not have an effect, " - "please use the new 'estimator' parameter to directly " - "give an aeon clusterer as input.", - FutureWarning, - stacklevel=2, - ) - latent_space = self.model_.layers[1].predict(X) self._estimator.fit(X=latent_space) diff --git a/examples/networks/deep_learning.ipynb b/examples/networks/deep_learning.ipynb index 43ec5b0353..cbad5df130 100644 --- a/examples/networks/deep_learning.ipynb +++ b/examples/networks/deep_learning.ipynb @@ -281,7 +281,7 @@ "aefcn = AEFCNClusterer(\n", " n_clusters=2,\n", " temporal_latent_space=False,\n", - " clustering_algorithm=\"kmeans\",\n", + " estimator=\"kmeans\",\n", " n_epochs=10,\n", ")\n", "\n",