From a78b71306c3e8da80f8a606c7b0f8f072eef582d Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Sun, 6 Apr 2025 10:05:46 +0200 Subject: [PATCH 1/7] A fix to inconsistent ticks in Base module --- aeon/base/_base.py | 91 ++++++++++++++++++----------------- aeon/base/_base_collection.py | 79 +++++++++++++++--------------- aeon/base/_base_series.py | 75 +++++++++++++++-------------- aeon/base/_compose.py | 41 ++++++++-------- 4 files changed, 150 insertions(+), 136 deletions(-) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index 84ab552db0..ded0d576cf 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -1,4 +1,4 @@ -"""Base class template for aeon estimators.""" +"""Base class template for ``aeon`` estimators.""" __maintainer__ = ["MatthewMiddlehurst", "TonyBagnall"] __all__ = ["BaseAeonEstimator"] @@ -17,23 +17,24 @@ class BaseAeonEstimator(BaseEstimator, ABC): """ - Base class for defining estimators in aeon. + Base class for defining estimators in ``aeon``. Contains the following methods: - - reset estimator to post-init - reset(keep) - - clone stimator (copy) - clone(random_state) - - inspect tags (class method) - get_class_tags() - - inspect tags (one tag, class) - get_class_tag(tag_name, tag_value_default, - raise_error) - - inspect tags (all) - get_tags() - - inspect tags (one tag) - get_tag(tag_name, tag_value_default, raise_error) - - setting dynamic tags - set_tags(**tag_dict) - - get fitted parameters - get_fitted_params(deep) + - reset estimator to post-init - ``reset(keep)`` + - clone stimator (copy) - ``clone(random_state)`` + - inspect tags (class method) - ``get_class_tags()`` + - inspect tags (one tag, class) - ``get_class_tag(tag_name, tag_value_default + , raise_error)`` + - inspect tags (all) - ``get_tags()`` + - inspect tags (one tag) - ``get_tag(tag_name, tag_value_default + , raise_error)`` + - setting dynamic tags - ``set_tags(**tag_dict)`` + - get fitted parameters - ``get_fitted_params(deep)`` All estimators have the attribute: - - fitted state flag - is_fitted + - fitted state flag - `is_fitted` """ _tags = { @@ -59,33 +60,33 @@ def reset(self, keep=None): """ Reset the object to a clean post-init state. - After a ``self.reset()`` call, self is equal or similar in value to + After a ``self.reset()`` call, `self` is equal or similar in value to ``type(self)(**self.get_params(deep=False))``, assuming no other attributes - were kept using ``keep``. + were kept using `keep`. Detailed behaviour: removes any object attributes, except: hyper-parameters (arguments of ``__init__``) - object attributes containing double-underscores, i.e., the string "__" + object attributes containing double-underscores, i.e., the string `"__"` runs ``__init__`` with current values of hyperparameters (result of ``get_params``) Not affected by the reset are: object attributes containing double-underscores class and object methods, class attributes - any attributes specified in the ``keep`` argument + any attributes specified in the `keep` argument Parameters ---------- keep : None, str, or list of str, default=None - If None, all attributes are removed except hyperparameters. - If str, only the attribute with this name is kept. - If list of str, only the attributes with these names are kept. + If ``None``, all attributes are removed except hyperparameters. + If ``str``, only the attribute with this name is kept. + If ``list`` of ``str``, only the attributes with these names are kept. Returns ------- self : object - Reference to self. + Reference to `self`. """ # retrieve parameters to copy them later params = self.get_params(deep=False) @@ -120,15 +121,16 @@ def clone(self, random_state=None): Obtain a clone of the object with the same hyperparameters. A clone is a different object without shared references, in post-init state. - This function is equivalent to returning ``sklearn.clone`` of self. + This function is equivalent to returning ``sklearn.clone`` of `self`. Equal in value to ``type(self)(**self.get_params(deep=False))``. Parameters ---------- random_state : int, RandomState instance, or None, default=None - Sets the random state of the clone. If None, the random state is not set. - If int, random_state is the seed used by the random number generator. - If RandomState instance, random_state is the random number generator. + Sets the random state of the clone. If ``None``, the random state is not + set. + If ``int``, `random_state` is the seed used by the random number generator. + If ``RandomState`` instance, `random_state` is the random number generator. Returns ------- @@ -182,7 +184,7 @@ def get_class_tag( tag_name : str Name of tag value. raise_error : bool, default=True - Whether a ValueError is raised when the tag is not found. + Whether a ``ValueError`` is raised when the tag is not found. tag_value_default : any type, default=None Default/fallback value if tag is not found and error is not raised. @@ -190,13 +192,13 @@ def get_class_tag( ------- tag_value Value of the ``tag_name`` tag in cls. - If not found, returns an error if ``raise_error`` is True, otherwise it + If not found, returns an error if ``raise_error`` is ``True``, otherwise it returns ``tag_value_default``. Raises ------ ValueError - if ``raise_error`` is True and ``tag_name`` is not in + if ``raise_error`` is ``True`` and ``tag_name`` is not in ``self.get_tags().keys()`` Examples @@ -242,7 +244,7 @@ def get_tag(self, tag_name, raise_error=True, tag_value_default=None): tag_name : str Name of tag to be retrieved. raise_error : bool, default=True - Whether a ValueError is raised when the tag is not found. + Whether a ``ValueError`` is raised when the tag is not found. tag_value_default : any type, default=None Default/fallback value if tag is not found and error is not raised. @@ -250,7 +252,7 @@ def get_tag(self, tag_name, raise_error=True, tag_value_default=None): ------- tag_value Value of the ``tag_name`` tag in self. - If not found, returns an error if ``raise_error`` is True, otherwise it + If not found, returns an error if ``raise_error`` is ``True``, otherwise it returns ``tag_value_default``. Raises @@ -287,7 +289,7 @@ def set_tags(self, **tag_dict): Returns ------- self : object - Reference to self. + Reference to `self`. """ tag_update = deepcopy(tag_dict) self._tags_dynamic.update(tag_update) @@ -302,7 +304,7 @@ def get_fitted_params(self, deep=True): Parameters ---------- deep : bool, default=True - If True, will return the fitted parameters for this estimator and + If ``True``, will return the fitted parameters for this estimator and contained subobjects that are estimators. Returns @@ -366,9 +368,10 @@ def _get_test_params(cls, parameter_set="default"): 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. + 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. """ # default parameters = empty dict return {} @@ -378,8 +381,8 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): """ Construct Estimator instance if possible. - Calls the `_get_test_params` method and returns an instance or list of instances - using the returned dict or list of dict. + Calls the ``_get_test_params`` method and returns an instance or ``list`` + of instances using the returned ``dict`` or list of ``dict``. Parameters ---------- @@ -387,14 +390,14 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): 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. return_first : bool, default=True - If True, return the first instance of the list of instances. - If False, return the list of instances. + If ``True``, return the first instance of the list of instances. + If ``False``, return the list of instances. Returns ------- instance : BaseAeonEstimator or list of BaseAeonEstimator - Instance of the class with default parameters. If return_first - is False, returns list of instances. + Instance of the class with default parameters. If `return_first` + is ``False``, returns list of instances. """ params = cls._get_test_params(parameter_set=parameter_set) @@ -416,7 +419,7 @@ def __sklearn_is_fitted__(self): return self.is_fitted def __sklearn_tags__(self): - """Return sklearn style tags for the estimator.""" + """Return ``sklearn`` style tags for the estimator.""" aeon_tags = self.get_tags() sklearn_tags = super().__sklearn_tags__() sklearn_tags.non_deterministic = aeon_tags.get("non_deterministic", False) @@ -428,13 +431,13 @@ def __sklearn_tags__(self): return sklearn_tags def _validate_data(self, **kwargs): - """Sklearn data validation.""" + """``Sklearn`` data validation.""" raise NotImplementedError( "aeon estimators do not have a _validate_data method." ) def get_metadata_routing(self): - """Sklearn metadata routing. + """``Sklearn`` metadata routing. Not supported by ``aeon`` estimators. """ @@ -444,7 +447,7 @@ def get_metadata_routing(self): @classmethod def _get_default_requests(cls): - """Sklearn metadata request defaults.""" + """``Sklearn`` metadata request defaults.""" from sklearn.utils._metadata_requests import MetadataRequest return MetadataRequest(None) diff --git a/aeon/base/_base_collection.py b/aeon/base/_base_collection.py index 4d7f4b4564..98e69ed768 100644 --- a/aeon/base/_base_collection.py +++ b/aeon/base/_base_collection.py @@ -4,19 +4,19 @@ class name: BaseCollectionEstimator Defining methods: - preprocessing - _preprocess_collection(self, X, store_metadata=True) - input checking - _check_X(self, X) - input conversion - _convert_X(self, X) - shape checking - _check_shape(self, X) + preprocessing - ``_preprocess_collection(self, X, store_metadata=True)`` + input checking - ``_check_X(self, X)`` + input conversion - ``_convert_X(self, X)`` + shape checking - ``_check_shape(self, X)`` Inherited inspection methods: - hyper-parameter inspection - get_params() - fitted parameter inspection - get_fitted_params() + hyper-parameter inspection - ``get_params()`` + fitted parameter inspection - ``get_fitted_params()`` State: - fitted model/strategy - by convention, any attributes ending in "_" - fitted state flag - is_fitted (property) - fitted state inspection - check_is_fitted() + fitted model/strategy - by convention, any attributes ending in `"_"` + fitted state flag - ``is_fitted (property)`` + fitted state inspection - ``check_is_fitted()`` """ @@ -80,26 +80,26 @@ def _preprocess_collection(self, X, store_metadata=True): Parameters ---------- X : collection - See aeon.utils.COLLECTIONS_DATA_TYPES for details on aeon supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported data structures. store_metadata : bool, default=True - Whether to store metadata about X in self.metadata_. + Whether to store metadata about ``X`` in ``self.metadata_``. Returns ------- X : collection - Processed X. A data structure of type self.get_tag("X_inner_type"). + Processed `X`. A data structure of type ``self.get_tag("X_inner_type")``. Raises ------ ValueError - If X is an invalid type or has characteristics that the estimator cannot + If `X` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _check_X : - Function that checks X is valid before conversion. + Function that checks `X` is valid before conversion. _convert_X : Function that converts to inner type. @@ -138,37 +138,39 @@ def _check_X(self, X): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the capabilities of the estimator against the metadata - for X i.e., univariate/multivariate, equal length/unequal length and no missing - values/missing values. + for `X` i.e., univariate/multivariate, equal length/unequal length + and no missing values/missing values. Parameters ---------- X : collection - See aeon.utils.COLLECTIONS_DATA_TYPES for details on aeon supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported data structures. Returns ------- metadata : dict - Metadata about X, with flags: - metadata["multivariate"] : whether X has more than one channel or not - metadata["missing_values"] : whether X has missing values or not - metadata["unequal_length"] : whether X contains unequal length series. - metadata["n_cases"] : number of cases in X - metadata["n_channels"] : number of channels in X - metadata["n_timepoints"] : number of timepoints in X if equal length, else - None + Metadata about ``X``, with flags: + `metadata["multivariate"]` : whether `X` has more than one channel or + not + `metadata["missing_values"]` : whether `X` has missing values or not + `metadata["unequal_length"]` : whether `X` contains unequal length + series. + `metadata["n_cases"]` : number of cases in `X` + `metadata["n_channels"]` : number of channels in `X` + `metadata["n_timepoints"]` : number of timepoints in `X` if equal + length, else ``None`` Raises ------ ValueError - If X is an invalid type or has characteristics that the estimator cannot + If `X` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _convert_X : - Function that converts X after it has been checked. + Function that converts `X` after it has been checked. Examples -------- @@ -209,30 +211,31 @@ def _check_X(self, X): def _convert_X(self, X): """ - Convert X to type defined by tag X_inner_type. + Convert `X` to type defined by tag ``X_inner_type``. If the input data is already an allowed type, it is returned unchanged. - If multiple types are allowed by self, then the best one for the type of input - data is selected. So, for example, if X_inner_tag is ["np-list", "numpy3D"] - and an df-list is passed, it will be converted to numpy3D if the series - are equal length, and np-list if the series are unequal length. + If multiple types are allowed by ``self``, then the best + one for the type of input data is selected. So, for example, if + ``X_inner_tag`` is ["np-list", "numpy3D"] and an `df-list` is passed, it will + be converted to ``numpy3D`` if the series are equal length, and `np-list` + if the series are unequal length. Parameters ---------- X : collection - See aeon.utils.COLLECTIONS_DATA_TYPES for details on aeon supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported data structures. Returns ------- X : collection - Converted X. A data structure of type self.get_tag("X_inner_type"). + Converted `X`. A data structure of type ``self.get_tag("X_inner_type")``. See Also -------- _check_X : - Function that checks X is valid and finds metadata. + Function that checks `X` is valid and finds metadata. Examples -------- @@ -275,17 +278,17 @@ def _convert_X(self, X): def _check_shape(self, X): """ - Check that the shape of X is consistent with the data seen in fit. + Check that the shape of `X` is consistent with the data seen in fit. Parameters ---------- X : data structure - Must be of type aeon.registry.COLLECTIONS_DATA_TYPES. + Must be of type ``aeon.registry.COLLECTIONS_DATA_TYPES``. Raises ------ ValueError - If the shape of X is not consistent with the data seen in fit. + If the shape of `X` is not consistent with the data seen in fit. """ # if metadata is empty, then we have not seen any data in fit. If the estimator # has not been fitted, then _is_fitted should catch this. diff --git a/aeon/base/_base_series.py b/aeon/base/_base_series.py index 6c86940f5b..56af8fa874 100644 --- a/aeon/base/_base_series.py +++ b/aeon/base/_base_series.py @@ -34,25 +34,25 @@ class BaseSeriesEstimator(BaseAeonEstimator): It also stores the common default tags used by all the subclasses and meta data describing the characteristics of time series passed to ``fit``. - Input and internal data format (where ``m`` is the number of time points and ``d`` + Input and internal data format (where `m` is the number of time points and `d` is the number of channels): Univariate series: - np.ndarray, shape ``(m,)``, ``(m, 1)`` or ``(1, m)`` depending on axis. - This is converted to a 2D np.ndarray internally. - pd.DataFrame, shape ``(m, 1)`` or ``(1, m)`` depending on axis. - pd.Series, shape ``(m,)`` is converted to a pd.DataFrame. + np.ndarray, shape `(m,)`, `(m, 1)` or `(1, m)` depending on axis. + This is converted to a 2D ``np.ndarray`` internally. + pd.DataFrame, shape `(m, 1)` or `(1, m)` depending on axis. + pd.Series, shape `(m,)` is converted to a ``pd.DataFrame``. Multivariate series: - np.ndarray array, shape ``(m, d)`` or ``(d, m)`` depending on axis. - pd.DataFrame ``(m, d)`` or ``(d, m)`` depending on axis. + ``np.ndarray`` array, shape `(m, d)` or `(d, m)` depending on axis. + ``pd.DataFrame`` `(m, d)` or `(d, m)` depending on axis. Parameters ---------- axis : int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels, n_timepoints)``. + `(n_channels, n_timepoints)`. Setting this class variable will convert the input data to the chosen axis. """ @@ -70,29 +70,31 @@ def __init__(self, axis): super().__init__() def _preprocess_series(self, X, axis, store_metadata): - """Preprocess input X prior to call to fit. + """Preprocess input `X` prior to call to fit. - Checks the characteristics of X, store metadata, checks self can handle - the data then convert X to X_inner_type + Checks the characteristics of `X`, store metadata, checks self can handle + the data then convert `X` to X_inner_type Parameters ---------- X: one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES A valid aeon time series data structure. See - aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types. + ``aeon.base._base_series.VALID_SERIES_INPUT_TYPES`` + for aeon supported types. axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels, n_timepoints)``. + `(n_channels, n_timepoints)`. store_metadata: bool - If True, overwrite metadata with the new metadata from X. + If ``True``, overwrite metadata with the new metadata from X. Returns ------- X: one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES - Input time series with data structure of type self.get_tag("X_inner_type"). + Input time series with data structure of type + ``self.get_tag("X_inner_type")``. """ meta = self._check_X(X, axis) if store_metadata: @@ -104,28 +106,29 @@ def _check_X(self, X, axis): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the - capabilities of the estimator against the metadata for X for + capabilities of the estimator against the metadata for `X` for univariate/multivariate and no missing values/missing values. Parameters ---------- X: one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES A valid aeon time series data structure. See - aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types. + ``aeon.base._base_series.VALID_SERIES_INPUT_TYPES`` + for aeon supported types. axis: int - The time point axis of the input series if it is 2D. If ``axis==0``, it is + The time point axis of the input series if it is `2D`. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints,n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints,n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels,n_timepoints)``. + `(n_channels,n_timepoints)`. Returns ------- metadata: dict - Metadata about X, with flags: - metadata["multivariate"]: whether X has more than one channel or not - metadata["n_channels"]: number of channels in X - metadata["missing_values"]: whether X has missing values or not + Metadata about `X`, with flags: + ``metadata["multivariate"]``: whether `X` has more than one channel or not + ``metadata["n_channels"]``: number of channels in `X` + ``metadata["missing_values"]``: whether `X` has missing values or not """ if axis > 1 or axis < 0: raise ValueError(f"Input axis should be 0 or 1, saw {axis}") @@ -192,32 +195,34 @@ def _check_X(self, X, axis): return metadata def _convert_X(self, X, axis): - """Convert input X to internal estimator datatype. + """Convert input `X` to internal estimator datatype. - Converts input X to the internal data type of the estimator using - self.get_tag("X_inner_type"). 1D numpy arrays are converted to 2D, + Converts input `X` to the internal data type of the estimator using + ``self.get_tag("X_inner_type")``. 1D numpy arrays are converted to 2D, and the data will be transposed if the input axis does not match that of the estimator. - Attempting to convert to a pd.Series for multivariate data or estimators will - raise an error. + Attempting to convert to a ``pd.Series`` for multivariate + data or estimators will raise an error. Parameters ---------- X: one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES A valid aeon time series data structure. See - aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types. + ``aeon.base._base_series.VALID_SERIES_INPUT_TYPES`` for aeon + supported types. axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels, n_timepoints)``. + `(n_channels, n_timepoints)`. Returns ------- X: one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES - Input time series with data structure of type self.get_tag("X_inner_type"). + Input time series with data structure of type + ``self.get_tag("X_inner_type")``. """ if axis > 1 or axis < 0: raise ValueError(f"Input axis should be 0 or 1, saw {axis}") diff --git a/aeon/base/_compose.py b/aeon/base/_compose.py index 0995e85de6..a3b2021047 100644 --- a/aeon/base/_compose.py +++ b/aeon/base/_compose.py @@ -12,8 +12,8 @@ class ComposableEstimatorMixin(ABC): """Handles parameter management for estimators composed of named estimators. - Parts (i.e. get_params and set_params) adapted or copied from the scikit-learn - ``_BaseComposition`` class in utils/metaestimators.py. + Parts (i.e. ``get_params`` and ``set_params``) adapted or copied from the + ``scikit-learn`` ``_BaseComposition`` class in ``utils/metaestimators.py``. """ # Attribute name containing an iterable of processed (str, estimator) tuples @@ -36,7 +36,7 @@ def get_params(self, deep=True): Parameters ---------- deep : bool, default=True - If True, will return the parameters for this estimator and + If ``True``, will return the parameters for this estimator and contained subobjects that are estimators. Returns @@ -113,7 +113,7 @@ def get_fitted_params(self, deep=True): Parameters ---------- deep : bool, default=True - If True, will return the fitted parameters for this estimator and + If ``True``, will return the fitted parameters for this estimator and contained subobjects that are estimators. Returns @@ -150,22 +150,22 @@ def _check_estimators( Parameters ---------- estimators : list - A list of estimators or list of (str, estimator) tuples. + A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples. attr_name : str, optional. Default = "steps" Name of checked attribute in error messages class_type : class, tuple of class or None, default=BaseAeonEstimator. - Class(es) that all estimators in ``estimators`` are checked to be an + Class(es) that all estimators in `estimators` are checked to be an instance of. allow_tuples : boolean, default=True. - Whether tuples of (str, estimator) are allowed in ``estimators``. - Generally, the end-state we want is a list of tuples, so this should be True - in most cases. + Whether tuples of (str, estimator) are allowed in `estimators`. + Generally, the end-state we want is a ``list`` of tuples, so this should be + ``True`` in most cases. allow_single_estimators : boolean, default=True. - Whether non-tuple estimator classes are allowed in ``estimators``. + Whether non-tuple estimator classes are allowed in `estimators`. unique_names : boolean, default=True. Whether to check that all tuple strings in `estimators` are unique. invalid_names : str, list of str or None, default=None. - Names that are invalid for estimators in ``estimators``. + Names that are invalid for estimators in `estimators`. Raises ------ @@ -233,22 +233,25 @@ def _check_estimators( def _convert_estimators(self, estimators, clone_estimators=True): """Convert estimators to list of (str, estimator) tuples. - Assumes ``_check_estimators`` has already been called on ``estimators``. + Assumes ``_check_estimators`` has already been called on `estimators`. Parameters ---------- - estimators : list of estimators, or list of (str, estimator tuples) - A list of estimators or list of (str, estimator) tuples to be converted. + estimators : list of estimators, or list of (str, estimator) tuples. + A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples + to be converted. clone_estimators : boolean, default=True. - Whether to return clone of estimators in ``estimators`` (True) or - references (False). + Whether to return clone of estimators in `estimators` (``True``) or + references (``False``). Returns ------- estimator_tuples : list of (str, estimator) tuples - If estimators was a list of (str, estimator) tuples, then identical/cloned - to ``estimators``. - if was a list of estimators or mixed, then unique str are generated to + If `estimators` was a ``list`` of (``str``, `estimator`) tuples, then + identical/cloned + to `estimators`. + if was a ``list`` of `estimators` or mixed, then unique ``str`` + are generated to create tuples. """ cloned_ests = [] From 835ce46477982d75be2c5cc1da90d29b763d10a4 Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Sun, 6 Apr 2025 11:23:56 +0200 Subject: [PATCH 2/7] A fix to inconsistent ticks in Base module --- aeon/base/_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index ded0d576cf..95fc1e7439 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -79,14 +79,14 @@ class and object methods, class attributes Parameters ---------- keep : None, str, or list of str, default=None - If ``None``, all attributes are removed except hyperparameters. - If ``str``, only the attribute with this name is kept. - If ``list`` of ``str``, only the attributes with these names are kept. + If ``None``, all attributes are removed except hyperparameters. + If ``str``, only the attribute with this name is kept. + If ``list`` of ``str``, only the attributes with these names are kept. Returns ------- self : object - Reference to `self`. + Reference to self. """ # retrieve parameters to copy them later params = self.get_params(deep=False) From 56704c2fff7fb6a9c3de0b0c90a16f947501ffe5 Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Sun, 6 Apr 2025 11:40:30 +0200 Subject: [PATCH 3/7] A fix to inconsistent ticks in Base module --- aeon/base/_base_collection.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aeon/base/_base_collection.py b/aeon/base/_base_collection.py index 98e69ed768..54d601a7f0 100644 --- a/aeon/base/_base_collection.py +++ b/aeon/base/_base_collection.py @@ -10,13 +10,13 @@ class name: BaseCollectionEstimator shape checking - ``_check_shape(self, X)`` Inherited inspection methods: - hyper-parameter inspection - ``get_params()`` - fitted parameter inspection - ``get_fitted_params()`` + hyper-parameter inspection - `get_params()` + fitted parameter inspection - `get_fitted_params()` State: fitted model/strategy - by convention, any attributes ending in `"_"` - fitted state flag - ``is_fitted (property)`` - fitted state inspection - ``check_is_fitted()`` + fitted state flag - `is_fitted` (property) + fitted state inspection - `check_is_fitted()` """ From c2d39fb20601087c9a167d1984863d17d266549c Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Sun, 6 Apr 2025 11:44:23 +0200 Subject: [PATCH 4/7] Revert "A fix to inconsistent ticks in Base module" This reverts commit 56704c2fff7fb6a9c3de0b0c90a16f947501ffe5. --- aeon/base/_base_collection.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aeon/base/_base_collection.py b/aeon/base/_base_collection.py index 54d601a7f0..98e69ed768 100644 --- a/aeon/base/_base_collection.py +++ b/aeon/base/_base_collection.py @@ -10,13 +10,13 @@ class name: BaseCollectionEstimator shape checking - ``_check_shape(self, X)`` Inherited inspection methods: - hyper-parameter inspection - `get_params()` - fitted parameter inspection - `get_fitted_params()` + hyper-parameter inspection - ``get_params()`` + fitted parameter inspection - ``get_fitted_params()`` State: fitted model/strategy - by convention, any attributes ending in `"_"` - fitted state flag - `is_fitted` (property) - fitted state inspection - `check_is_fitted()` + fitted state flag - ``is_fitted (property)`` + fitted state inspection - ``check_is_fitted()`` """ From 2ce1b09af8394154eaa5ce945d81aee55095dea2 Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Tue, 15 Apr 2025 16:25:39 +0200 Subject: [PATCH 5/7] inconsistent backticks in base module --- aeon/base/_base.py | 46 +++++++++++++++++--------------- aeon/base/_base_collection.py | 48 ++++++++++++++++----------------- aeon/base/_base_series.py | 50 +++++++++++++++++------------------ aeon/base/_compose.py | 25 +++++++++--------- 4 files changed, 85 insertions(+), 84 deletions(-) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index 7a34de9ef1..4fec16ba4a 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -1,4 +1,4 @@ -"""Base class template for ``aeon`` estimators.""" +"""Base class template for aeon estimators.""" __maintainer__ = ["MatthewMiddlehurst", "TonyBagnall"] __all__ = ["BaseAeonEstimator"] @@ -17,7 +17,7 @@ class BaseAeonEstimator(BaseEstimator, ABC): """ - Base class for defining estimators in ``aeon``. + Base class for defining estimators in aeon. Contains the following methods: @@ -25,16 +25,16 @@ class BaseAeonEstimator(BaseEstimator, ABC): - clone stimator (copy) - ``clone(random_state)`` - inspect tags (class method) - ``get_class_tags()`` - inspect tags (one tag, class) - ``get_class_tag(tag_name, tag_value_default - , raise_error)`` + , raise_error)`` - inspect tags (all) - ``get_tags()`` - inspect tags (one tag) - ``get_tag(tag_name, tag_value_default - , raise_error)`` + , raise_error)`` - setting dynamic tags - ``set_tags(**tag_dict)`` - get fitted parameters - ``get_fitted_params(deep)`` All estimators have the attribute: - - fitted state flag - `is_fitted` + - fitted state flag - ``is_fitted`` """ _tags = { @@ -60,21 +60,21 @@ def reset(self, keep=None): """ Reset the object to a clean post-init state. - After a ``self.reset()`` call, `self` is equal or similar in value to + After a ``self.reset()`` call, ``self`` is equal or similar in value to ``type(self)(**self.get_params(deep=False))``, assuming no other attributes - were kept using `keep`. + were kept using ``keep``. Detailed behaviour: removes any object attributes, except: hyper-parameters (arguments of ``__init__``) - object attributes containing double-underscores, i.e., the string `"__"` + object attributes containing double-underscores, i.e., the string ``__`` runs ``__init__`` with current values of hyperparameters (result of ``get_params``) Not affected by the reset are: object attributes containing double-underscores class and object methods, class attributes - any attributes specified in the `keep` argument + any attributes specified in the ``keep`` argument Parameters ---------- @@ -126,7 +126,7 @@ def clone(self, random_state=None): Obtain a clone of the object with the same hyperparameters. A clone is a different object without shared references, in post-init state. - This function is equivalent to returning ``sklearn.clone`` of `self`. + This function is equivalent to returning ``sklearn.clone`` of ``self``. Equal in value to ``type(self)(**self.get_params(deep=False))``. Parameters @@ -134,8 +134,10 @@ def clone(self, random_state=None): random_state : int, RandomState instance, or None, default=None Sets the random state of the clone. If ``None``, the random state is not set. - If ``int``, `random_state` is the seed used by the random number generator. - If ``RandomState`` instance, `random_state` is the random number generator. + If ``int``, ``random_state`` is the seed used by the random number + generator. + If ``RandomState`` instance, ``random_state`` is the random number + generator. Returns ------- @@ -294,7 +296,7 @@ def set_tags(self, **tag_dict): Returns ------- self : object - Reference to `self`. + Reference to ``self``. """ tag_update = deepcopy(tag_dict) self._tags_dynamic.update(tag_update) @@ -356,7 +358,7 @@ def _check_is_fitted(self): if not self.is_fitted: raise NotFittedError( f"This instance of {self.__class__.__name__} has not " - f"been fitted yet; please call `fit` first." + f"been fitted yet; please call ``fit`` first." ) @classmethod @@ -368,13 +370,13 @@ def _get_test_params(cls, parameter_set="default"): ---------- 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. + 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., + parameters to construct an ``interesting`` test instance, i.e., ``MyClass(**params)`` or ``MyClass(**params[i])`` creates a valid test instance. """ @@ -393,7 +395,7 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): ---------- 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. + special parameters are defined for a value, will return ``default`` set. return_first : bool, default=True If ``True``, return the first instance of the list of instances. If ``False``, return the list of instances. @@ -401,7 +403,7 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): Returns ------- instance : BaseAeonEstimator or list of BaseAeonEstimator - Instance of the class with default parameters. If `return_first` + Instance of the class with default parameters. If ``return_first`` is ``False``, returns list of instances. """ params = cls._get_test_params(parameter_set=parameter_set) @@ -436,15 +438,15 @@ def __sklearn_tags__(self): return sklearn_tags def _validate_data(self, **kwargs): - """``Sklearn`` data validation.""" + """Sklearn data validation.""" raise NotImplementedError( "aeon estimators do not have a _validate_data method." ) def get_metadata_routing(self): - """``Sklearn`` metadata routing. + """Sklearn metadata routing. - Not supported by ``aeon`` estimators. + Not supported by aeon estimators. """ raise NotImplementedError( "aeon estimators do not have a get_metadata_routing method." @@ -452,7 +454,7 @@ def get_metadata_routing(self): @classmethod def _get_default_requests(cls): - """``Sklearn`` metadata request defaults.""" + """Sklearn metadata request defaults.""" from sklearn.utils._metadata_requests import MetadataRequest return MetadataRequest(None) diff --git a/aeon/base/_base_collection.py b/aeon/base/_base_collection.py index 98e69ed768..3ddabbc42f 100644 --- a/aeon/base/_base_collection.py +++ b/aeon/base/_base_collection.py @@ -14,7 +14,7 @@ class name: BaseCollectionEstimator fitted parameter inspection - ``get_fitted_params()`` State: - fitted model/strategy - by convention, any attributes ending in `"_"` + fitted model/strategy - by convention, any attributes ending in ``_`` fitted state flag - ``is_fitted (property)`` fitted state inspection - ``check_is_fitted()`` @@ -80,7 +80,7 @@ def _preprocess_collection(self, X, store_metadata=True): Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported data structures. store_metadata : bool, default=True Whether to store metadata about ``X`` in ``self.metadata_``. @@ -88,18 +88,18 @@ def _preprocess_collection(self, X, store_metadata=True): Returns ------- X : collection - Processed `X`. A data structure of type ``self.get_tag("X_inner_type")``. + Processed ``X``. A data structure of type ``self.get_tag("X_inner_type")``. Raises ------ ValueError - If `X` is an invalid type or has characteristics that the estimator cannot + If ``X`` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _check_X : - Function that checks `X` is valid before conversion. + Function that checks ``X`` is valid before conversion. _convert_X : Function that converts to inner type. @@ -138,39 +138,39 @@ def _check_X(self, X): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the capabilities of the estimator against the metadata - for `X` i.e., univariate/multivariate, equal length/unequal length + for ``X`` i.e., univariate/multivariate, equal length/unequal length and no missing values/missing values. Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported data structures. Returns ------- metadata : dict Metadata about ``X``, with flags: - `metadata["multivariate"]` : whether `X` has more than one channel or + ``metadata["multivariate"]`` : whether ``X`` has more than one channel or not - `metadata["missing_values"]` : whether `X` has missing values or not - `metadata["unequal_length"]` : whether `X` contains unequal length + ``metadata["missing_values"]`` : whether ``X`` has missing values or not + ``metadata["unequal_length"]`` : whether ``X`` contains unequal length series. - `metadata["n_cases"]` : number of cases in `X` - `metadata["n_channels"]` : number of channels in `X` - `metadata["n_timepoints"]` : number of timepoints in `X` if equal + ``metadata["n_cases"]`` : number of cases in ``X`` + ``metadata["n_channels"]`` : number of channels in ``X`` + ``metadata["n_timepoints"]`` : number of timepoints in ``X`` if equal length, else ``None`` Raises ------ ValueError - If `X` is an invalid type or has characteristics that the estimator cannot + If ``X`` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _convert_X : - Function that converts `X` after it has been checked. + Function that converts ``X`` after it has been checked. Examples -------- @@ -211,31 +211,31 @@ def _check_X(self, X): def _convert_X(self, X): """ - Convert `X` to type defined by tag ``X_inner_type``. + Convert ``X`` to type defined by tag ``X_inner_type``. If the input data is already an allowed type, it is returned unchanged. If multiple types are allowed by ``self``, then the best one for the type of input data is selected. So, for example, if - ``X_inner_tag`` is ["np-list", "numpy3D"] and an `df-list` is passed, it will - be converted to ``numpy3D`` if the series are equal length, and `np-list` - if the series are unequal length. + ``X_inner_tag`` is [``np-list``, ``numpy3D``] and an ``df-list`` is passed, + it will be converted to ``numpy3D`` if the series are equal length, and + ``np-list`` if the series are unequal length. Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported data structures. Returns ------- X : collection - Converted `X`. A data structure of type ``self.get_tag("X_inner_type")``. + Converted ``X``. A data structure of type ``self.get_tag("X_inner_type")``. See Also -------- _check_X : - Function that checks `X` is valid and finds metadata. + Function that checks ``X`` is valid and finds metadata. Examples -------- @@ -278,7 +278,7 @@ def _convert_X(self, X): def _check_shape(self, X): """ - Check that the shape of `X` is consistent with the data seen in fit. + Check that the shape of ``X`` is consistent with the data seen in fit. Parameters ---------- @@ -288,7 +288,7 @@ def _check_shape(self, X): Raises ------ ValueError - If the shape of `X` is not consistent with the data seen in fit. + If the shape of ``X`` is not consistent with the data seen in fit. """ # if metadata is empty, then we have not seen any data in fit. If the estimator # has not been fitted, then _is_fitted should catch this. diff --git a/aeon/base/_base_series.py b/aeon/base/_base_series.py index 56af8fa874..07af84817b 100644 --- a/aeon/base/_base_series.py +++ b/aeon/base/_base_series.py @@ -34,25 +34,25 @@ class BaseSeriesEstimator(BaseAeonEstimator): It also stores the common default tags used by all the subclasses and meta data describing the characteristics of time series passed to ``fit``. - Input and internal data format (where `m` is the number of time points and `d` + Input and internal data format (where ``m`` is the number of time points and ``d`` is the number of channels): Univariate series: - np.ndarray, shape `(m,)`, `(m, 1)` or `(1, m)` depending on axis. + np.ndarray, shape ``(m,)``, ``(m, 1)`` or ``(1, m)`` depending on axis. This is converted to a 2D ``np.ndarray`` internally. - pd.DataFrame, shape `(m, 1)` or `(1, m)` depending on axis. - pd.Series, shape `(m,)` is converted to a ``pd.DataFrame``. + pd.DataFrame, shape ``(m, 1)`` or ``(1, m)`` depending on axis. + pd.Series, shape ``(m,)`` is converted to a ``pd.DataFrame``. Multivariate series: - ``np.ndarray`` array, shape `(m, d)` or `(d, m)` depending on axis. - ``pd.DataFrame`` `(m, d)` or `(d, m)` depending on axis. + ``np.ndarray`` array, shape ``(m, d)`` or ``(d, m)`` depending on axis. + ``pd.DataFrame`` ``(m, d)`` or ``(d, m)`` depending on axis. Parameters ---------- axis : int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels, n_timepoints)`. + ``(n_channels, n_timepoints)``. Setting this class variable will convert the input data to the chosen axis. """ @@ -70,10 +70,10 @@ def __init__(self, axis): super().__init__() def _preprocess_series(self, X, axis, store_metadata): - """Preprocess input `X` prior to call to fit. + """Preprocess input ``X`` prior to call to fit. - Checks the characteristics of `X`, store metadata, checks self can handle - the data then convert `X` to X_inner_type + Checks the characteristics of ``X``, store metadata, checks self can handle + the data then convert ``X`` to X_inner_type Parameters ---------- @@ -84,9 +84,9 @@ def _preprocess_series(self, X, axis, store_metadata): axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels, n_timepoints)`. + ``(n_channels, n_timepoints)``. store_metadata: bool If ``True``, overwrite metadata with the new metadata from X. @@ -106,7 +106,7 @@ def _check_X(self, X, axis): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the - capabilities of the estimator against the metadata for `X` for + capabilities of the estimator against the metadata for ``X`` for univariate/multivariate and no missing values/missing values. Parameters @@ -116,19 +116,19 @@ def _check_X(self, X, axis): ``aeon.base._base_series.VALID_SERIES_INPUT_TYPES`` for aeon supported types. axis: int - The time point axis of the input series if it is `2D`. If ``axis==0``, it is + The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints,n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints,n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels,n_timepoints)`. + ``(n_channels,n_timepoints)``. Returns ------- metadata: dict - Metadata about `X`, with flags: - ``metadata["multivariate"]``: whether `X` has more than one channel or not - ``metadata["n_channels"]``: number of channels in `X` - ``metadata["missing_values"]``: whether `X` has missing values or not + Metadata about ``X``, with flags: + ``metadata["multivariate"]``: whether ``X`` has more than one channel or not + ``metadata["n_channels"]``: number of channels in ``X`` + ``metadata["missing_values"]``: whether ``X`` has missing values or not """ if axis > 1 or axis < 0: raise ValueError(f"Input axis should be 0 or 1, saw {axis}") @@ -195,9 +195,9 @@ def _check_X(self, X, axis): return metadata def _convert_X(self, X, axis): - """Convert input `X` to internal estimator datatype. + """Convert input ``X`` to internal estimator datatype. - Converts input `X` to the internal data type of the estimator using + Converts input ``X`` to the internal data type of the estimator using ``self.get_tag("X_inner_type")``. 1D numpy arrays are converted to 2D, and the data will be transposed if the input axis does not match that of the estimator. @@ -214,9 +214,9 @@ def _convert_X(self, X, axis): axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels, n_timepoints)`. + ``(n_channels, n_timepoints)``. Returns ------- diff --git a/aeon/base/_compose.py b/aeon/base/_compose.py index a3b2021047..fa166e52bf 100644 --- a/aeon/base/_compose.py +++ b/aeon/base/_compose.py @@ -150,22 +150,22 @@ def _check_estimators( Parameters ---------- estimators : list - A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples. + A ``list`` of estimators or ``list`` of (``str``, ``estimator``) tuples. attr_name : str, optional. Default = "steps" Name of checked attribute in error messages class_type : class, tuple of class or None, default=BaseAeonEstimator. - Class(es) that all estimators in `estimators` are checked to be an + Class(es) that all estimators in ``estimators`` are checked to be an instance of. allow_tuples : boolean, default=True. - Whether tuples of (str, estimator) are allowed in `estimators`. + Whether tuples of (str, estimator) are allowed in ``estimators``. Generally, the end-state we want is a ``list`` of tuples, so this should be ``True`` in most cases. allow_single_estimators : boolean, default=True. - Whether non-tuple estimator classes are allowed in `estimators`. + Whether non-tuple estimator classes are allowed in ``estimators``. unique_names : boolean, default=True. - Whether to check that all tuple strings in `estimators` are unique. + Whether to check that all tuple strings in ``estimators`` are unique. invalid_names : str, list of str or None, default=None. - Names that are invalid for estimators in `estimators`. + Names that are invalid for estimators in ``estimators``. Raises ------ @@ -233,24 +233,23 @@ def _check_estimators( def _convert_estimators(self, estimators, clone_estimators=True): """Convert estimators to list of (str, estimator) tuples. - Assumes ``_check_estimators`` has already been called on `estimators`. + Assumes ``_check_estimators`` has already been called on ``estimators``. Parameters ---------- estimators : list of estimators, or list of (str, estimator) tuples. - A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples + A ``list`` of estimators or ``list`` of (``str``, ``estimator``) tuples to be converted. clone_estimators : boolean, default=True. - Whether to return clone of estimators in `estimators` (``True``) or + Whether to return clone of estimators in ``estimators`` (``True``) or references (``False``). Returns ------- estimator_tuples : list of (str, estimator) tuples - If `estimators` was a ``list`` of (``str``, `estimator`) tuples, then - identical/cloned - to `estimators`. - if was a ``list`` of `estimators` or mixed, then unique ``str`` + If ``estimators`` was a ``list`` of (``str``, ``estimator``) tuples, then + identical/cloned to ``estimators``. + if was a ``list`` of ``estimators`` or mixed, then unique ``str`` are generated to create tuples. """ From 54fda165c0dd497af3e0f3383460db7f4b93dc63 Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Tue, 15 Apr 2025 16:33:10 +0200 Subject: [PATCH 6/7] Revert "inconsistent backticks in base module" This reverts commit d4f98bd644c17b49fee6d7388d2ac63d1ab59a5e. --- aeon/base/_base.py | 46 +++++++++++++++----------------- aeon/base/_base_collection.py | 48 ++++++++++++++++----------------- aeon/base/_base_series.py | 50 +++++++++++++++++------------------ aeon/base/_compose.py | 25 +++++++++--------- 4 files changed, 84 insertions(+), 85 deletions(-) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index 4fec16ba4a..7a34de9ef1 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -1,4 +1,4 @@ -"""Base class template for aeon estimators.""" +"""Base class template for ``aeon`` estimators.""" __maintainer__ = ["MatthewMiddlehurst", "TonyBagnall"] __all__ = ["BaseAeonEstimator"] @@ -17,7 +17,7 @@ class BaseAeonEstimator(BaseEstimator, ABC): """ - Base class for defining estimators in aeon. + Base class for defining estimators in ``aeon``. Contains the following methods: @@ -25,16 +25,16 @@ class BaseAeonEstimator(BaseEstimator, ABC): - clone stimator (copy) - ``clone(random_state)`` - inspect tags (class method) - ``get_class_tags()`` - inspect tags (one tag, class) - ``get_class_tag(tag_name, tag_value_default - , raise_error)`` + , raise_error)`` - inspect tags (all) - ``get_tags()`` - inspect tags (one tag) - ``get_tag(tag_name, tag_value_default - , raise_error)`` + , raise_error)`` - setting dynamic tags - ``set_tags(**tag_dict)`` - get fitted parameters - ``get_fitted_params(deep)`` All estimators have the attribute: - - fitted state flag - ``is_fitted`` + - fitted state flag - `is_fitted` """ _tags = { @@ -60,21 +60,21 @@ def reset(self, keep=None): """ Reset the object to a clean post-init state. - After a ``self.reset()`` call, ``self`` is equal or similar in value to + After a ``self.reset()`` call, `self` is equal or similar in value to ``type(self)(**self.get_params(deep=False))``, assuming no other attributes - were kept using ``keep``. + were kept using `keep`. Detailed behaviour: removes any object attributes, except: hyper-parameters (arguments of ``__init__``) - object attributes containing double-underscores, i.e., the string ``__`` + object attributes containing double-underscores, i.e., the string `"__"` runs ``__init__`` with current values of hyperparameters (result of ``get_params``) Not affected by the reset are: object attributes containing double-underscores class and object methods, class attributes - any attributes specified in the ``keep`` argument + any attributes specified in the `keep` argument Parameters ---------- @@ -126,7 +126,7 @@ def clone(self, random_state=None): Obtain a clone of the object with the same hyperparameters. A clone is a different object without shared references, in post-init state. - This function is equivalent to returning ``sklearn.clone`` of ``self``. + This function is equivalent to returning ``sklearn.clone`` of `self`. Equal in value to ``type(self)(**self.get_params(deep=False))``. Parameters @@ -134,10 +134,8 @@ def clone(self, random_state=None): random_state : int, RandomState instance, or None, default=None Sets the random state of the clone. If ``None``, the random state is not set. - If ``int``, ``random_state`` is the seed used by the random number - generator. - If ``RandomState`` instance, ``random_state`` is the random number - generator. + If ``int``, `random_state` is the seed used by the random number generator. + If ``RandomState`` instance, `random_state` is the random number generator. Returns ------- @@ -296,7 +294,7 @@ def set_tags(self, **tag_dict): Returns ------- self : object - Reference to ``self``. + Reference to `self`. """ tag_update = deepcopy(tag_dict) self._tags_dynamic.update(tag_update) @@ -358,7 +356,7 @@ def _check_is_fitted(self): if not self.is_fitted: raise NotFittedError( f"This instance of {self.__class__.__name__} has not " - f"been fitted yet; please call ``fit`` first." + f"been fitted yet; please call `fit` first." ) @classmethod @@ -370,13 +368,13 @@ def _get_test_params(cls, parameter_set="default"): ---------- 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. + 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., + parameters to construct an `"interesting"` test instance, i.e., ``MyClass(**params)`` or ``MyClass(**params[i])`` creates a valid test instance. """ @@ -395,7 +393,7 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): ---------- 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. + special parameters are defined for a value, will return `"default"` set. return_first : bool, default=True If ``True``, return the first instance of the list of instances. If ``False``, return the list of instances. @@ -403,7 +401,7 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): Returns ------- instance : BaseAeonEstimator or list of BaseAeonEstimator - Instance of the class with default parameters. If ``return_first`` + Instance of the class with default parameters. If `return_first` is ``False``, returns list of instances. """ params = cls._get_test_params(parameter_set=parameter_set) @@ -438,15 +436,15 @@ def __sklearn_tags__(self): return sklearn_tags def _validate_data(self, **kwargs): - """Sklearn data validation.""" + """``Sklearn`` data validation.""" raise NotImplementedError( "aeon estimators do not have a _validate_data method." ) def get_metadata_routing(self): - """Sklearn metadata routing. + """``Sklearn`` metadata routing. - Not supported by aeon estimators. + Not supported by ``aeon`` estimators. """ raise NotImplementedError( "aeon estimators do not have a get_metadata_routing method." @@ -454,7 +452,7 @@ def get_metadata_routing(self): @classmethod def _get_default_requests(cls): - """Sklearn metadata request defaults.""" + """``Sklearn`` metadata request defaults.""" from sklearn.utils._metadata_requests import MetadataRequest return MetadataRequest(None) diff --git a/aeon/base/_base_collection.py b/aeon/base/_base_collection.py index 3ddabbc42f..98e69ed768 100644 --- a/aeon/base/_base_collection.py +++ b/aeon/base/_base_collection.py @@ -14,7 +14,7 @@ class name: BaseCollectionEstimator fitted parameter inspection - ``get_fitted_params()`` State: - fitted model/strategy - by convention, any attributes ending in ``_`` + fitted model/strategy - by convention, any attributes ending in `"_"` fitted state flag - ``is_fitted (property)`` fitted state inspection - ``check_is_fitted()`` @@ -80,7 +80,7 @@ def _preprocess_collection(self, X, store_metadata=True): Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported data structures. store_metadata : bool, default=True Whether to store metadata about ``X`` in ``self.metadata_``. @@ -88,18 +88,18 @@ def _preprocess_collection(self, X, store_metadata=True): Returns ------- X : collection - Processed ``X``. A data structure of type ``self.get_tag("X_inner_type")``. + Processed `X`. A data structure of type ``self.get_tag("X_inner_type")``. Raises ------ ValueError - If ``X`` is an invalid type or has characteristics that the estimator cannot + If `X` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _check_X : - Function that checks ``X`` is valid before conversion. + Function that checks `X` is valid before conversion. _convert_X : Function that converts to inner type. @@ -138,39 +138,39 @@ def _check_X(self, X): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the capabilities of the estimator against the metadata - for ``X`` i.e., univariate/multivariate, equal length/unequal length + for `X` i.e., univariate/multivariate, equal length/unequal length and no missing values/missing values. Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported data structures. Returns ------- metadata : dict Metadata about ``X``, with flags: - ``metadata["multivariate"]`` : whether ``X`` has more than one channel or + `metadata["multivariate"]` : whether `X` has more than one channel or not - ``metadata["missing_values"]`` : whether ``X`` has missing values or not - ``metadata["unequal_length"]`` : whether ``X`` contains unequal length + `metadata["missing_values"]` : whether `X` has missing values or not + `metadata["unequal_length"]` : whether `X` contains unequal length series. - ``metadata["n_cases"]`` : number of cases in ``X`` - ``metadata["n_channels"]`` : number of channels in ``X`` - ``metadata["n_timepoints"]`` : number of timepoints in ``X`` if equal + `metadata["n_cases"]` : number of cases in `X` + `metadata["n_channels"]` : number of channels in `X` + `metadata["n_timepoints"]` : number of timepoints in `X` if equal length, else ``None`` Raises ------ ValueError - If ``X`` is an invalid type or has characteristics that the estimator cannot + If `X` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _convert_X : - Function that converts ``X`` after it has been checked. + Function that converts `X` after it has been checked. Examples -------- @@ -211,31 +211,31 @@ def _check_X(self, X): def _convert_X(self, X): """ - Convert ``X`` to type defined by tag ``X_inner_type``. + Convert `X` to type defined by tag ``X_inner_type``. If the input data is already an allowed type, it is returned unchanged. If multiple types are allowed by ``self``, then the best one for the type of input data is selected. So, for example, if - ``X_inner_tag`` is [``np-list``, ``numpy3D``] and an ``df-list`` is passed, - it will be converted to ``numpy3D`` if the series are equal length, and - ``np-list`` if the series are unequal length. + ``X_inner_tag`` is ["np-list", "numpy3D"] and an `df-list` is passed, it will + be converted to ``numpy3D`` if the series are equal length, and `np-list` + if the series are unequal length. Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported data structures. Returns ------- X : collection - Converted ``X``. A data structure of type ``self.get_tag("X_inner_type")``. + Converted `X`. A data structure of type ``self.get_tag("X_inner_type")``. See Also -------- _check_X : - Function that checks ``X`` is valid and finds metadata. + Function that checks `X` is valid and finds metadata. Examples -------- @@ -278,7 +278,7 @@ def _convert_X(self, X): def _check_shape(self, X): """ - Check that the shape of ``X`` is consistent with the data seen in fit. + Check that the shape of `X` is consistent with the data seen in fit. Parameters ---------- @@ -288,7 +288,7 @@ def _check_shape(self, X): Raises ------ ValueError - If the shape of ``X`` is not consistent with the data seen in fit. + If the shape of `X` is not consistent with the data seen in fit. """ # if metadata is empty, then we have not seen any data in fit. If the estimator # has not been fitted, then _is_fitted should catch this. diff --git a/aeon/base/_base_series.py b/aeon/base/_base_series.py index 07af84817b..56af8fa874 100644 --- a/aeon/base/_base_series.py +++ b/aeon/base/_base_series.py @@ -34,25 +34,25 @@ class BaseSeriesEstimator(BaseAeonEstimator): It also stores the common default tags used by all the subclasses and meta data describing the characteristics of time series passed to ``fit``. - Input and internal data format (where ``m`` is the number of time points and ``d`` + Input and internal data format (where `m` is the number of time points and `d` is the number of channels): Univariate series: - np.ndarray, shape ``(m,)``, ``(m, 1)`` or ``(1, m)`` depending on axis. + np.ndarray, shape `(m,)`, `(m, 1)` or `(1, m)` depending on axis. This is converted to a 2D ``np.ndarray`` internally. - pd.DataFrame, shape ``(m, 1)`` or ``(1, m)`` depending on axis. - pd.Series, shape ``(m,)`` is converted to a ``pd.DataFrame``. + pd.DataFrame, shape `(m, 1)` or `(1, m)` depending on axis. + pd.Series, shape `(m,)` is converted to a ``pd.DataFrame``. Multivariate series: - ``np.ndarray`` array, shape ``(m, d)`` or ``(d, m)`` depending on axis. - ``pd.DataFrame`` ``(m, d)`` or ``(d, m)`` depending on axis. + ``np.ndarray`` array, shape `(m, d)` or `(d, m)` depending on axis. + ``pd.DataFrame`` `(m, d)` or `(d, m)` depending on axis. Parameters ---------- axis : int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels, n_timepoints)``. + `(n_channels, n_timepoints)`. Setting this class variable will convert the input data to the chosen axis. """ @@ -70,10 +70,10 @@ def __init__(self, axis): super().__init__() def _preprocess_series(self, X, axis, store_metadata): - """Preprocess input ``X`` prior to call to fit. + """Preprocess input `X` prior to call to fit. - Checks the characteristics of ``X``, store metadata, checks self can handle - the data then convert ``X`` to X_inner_type + Checks the characteristics of `X`, store metadata, checks self can handle + the data then convert `X` to X_inner_type Parameters ---------- @@ -84,9 +84,9 @@ def _preprocess_series(self, X, axis, store_metadata): axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels, n_timepoints)``. + `(n_channels, n_timepoints)`. store_metadata: bool If ``True``, overwrite metadata with the new metadata from X. @@ -106,7 +106,7 @@ def _check_X(self, X, axis): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the - capabilities of the estimator against the metadata for ``X`` for + capabilities of the estimator against the metadata for `X` for univariate/multivariate and no missing values/missing values. Parameters @@ -116,19 +116,19 @@ def _check_X(self, X, axis): ``aeon.base._base_series.VALID_SERIES_INPUT_TYPES`` for aeon supported types. axis: int - The time point axis of the input series if it is 2D. If ``axis==0``, it is + The time point axis of the input series if it is `2D`. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints,n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints,n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels,n_timepoints)``. + `(n_channels,n_timepoints)`. Returns ------- metadata: dict - Metadata about ``X``, with flags: - ``metadata["multivariate"]``: whether ``X`` has more than one channel or not - ``metadata["n_channels"]``: number of channels in ``X`` - ``metadata["missing_values"]``: whether ``X`` has missing values or not + Metadata about `X`, with flags: + ``metadata["multivariate"]``: whether `X` has more than one channel or not + ``metadata["n_channels"]``: number of channels in `X` + ``metadata["missing_values"]``: whether `X` has missing values or not """ if axis > 1 or axis < 0: raise ValueError(f"Input axis should be 0 or 1, saw {axis}") @@ -195,9 +195,9 @@ def _check_X(self, X, axis): return metadata def _convert_X(self, X, axis): - """Convert input ``X`` to internal estimator datatype. + """Convert input `X` to internal estimator datatype. - Converts input ``X`` to the internal data type of the estimator using + Converts input `X` to the internal data type of the estimator using ``self.get_tag("X_inner_type")``. 1D numpy arrays are converted to 2D, and the data will be transposed if the input axis does not match that of the estimator. @@ -214,9 +214,9 @@ def _convert_X(self, X, axis): axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates + shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - ``(n_channels, n_timepoints)``. + `(n_channels, n_timepoints)`. Returns ------- diff --git a/aeon/base/_compose.py b/aeon/base/_compose.py index fa166e52bf..a3b2021047 100644 --- a/aeon/base/_compose.py +++ b/aeon/base/_compose.py @@ -150,22 +150,22 @@ def _check_estimators( Parameters ---------- estimators : list - A ``list`` of estimators or ``list`` of (``str``, ``estimator``) tuples. + A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples. attr_name : str, optional. Default = "steps" Name of checked attribute in error messages class_type : class, tuple of class or None, default=BaseAeonEstimator. - Class(es) that all estimators in ``estimators`` are checked to be an + Class(es) that all estimators in `estimators` are checked to be an instance of. allow_tuples : boolean, default=True. - Whether tuples of (str, estimator) are allowed in ``estimators``. + Whether tuples of (str, estimator) are allowed in `estimators`. Generally, the end-state we want is a ``list`` of tuples, so this should be ``True`` in most cases. allow_single_estimators : boolean, default=True. - Whether non-tuple estimator classes are allowed in ``estimators``. + Whether non-tuple estimator classes are allowed in `estimators`. unique_names : boolean, default=True. - Whether to check that all tuple strings in ``estimators`` are unique. + Whether to check that all tuple strings in `estimators` are unique. invalid_names : str, list of str or None, default=None. - Names that are invalid for estimators in ``estimators``. + Names that are invalid for estimators in `estimators`. Raises ------ @@ -233,23 +233,24 @@ def _check_estimators( def _convert_estimators(self, estimators, clone_estimators=True): """Convert estimators to list of (str, estimator) tuples. - Assumes ``_check_estimators`` has already been called on ``estimators``. + Assumes ``_check_estimators`` has already been called on `estimators`. Parameters ---------- estimators : list of estimators, or list of (str, estimator) tuples. - A ``list`` of estimators or ``list`` of (``str``, ``estimator``) tuples + A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples to be converted. clone_estimators : boolean, default=True. - Whether to return clone of estimators in ``estimators`` (``True``) or + Whether to return clone of estimators in `estimators` (``True``) or references (``False``). Returns ------- estimator_tuples : list of (str, estimator) tuples - If ``estimators`` was a ``list`` of (``str``, ``estimator``) tuples, then - identical/cloned to ``estimators``. - if was a ``list`` of ``estimators`` or mixed, then unique ``str`` + If `estimators` was a ``list`` of (``str``, `estimator`) tuples, then + identical/cloned + to `estimators`. + if was a ``list`` of `estimators` or mixed, then unique ``str`` are generated to create tuples. """ From b18877cfbaf307f46fae6535347c1a05be4b1c16 Mon Sep 17 00:00:00 2001 From: Ahmed Zahran Date: Tue, 15 Apr 2025 17:01:59 +0200 Subject: [PATCH 7/7] fix inconsistent ticks in base module --- aeon/base/_base.py | 46 +++++++++++++++++--------------- aeon/base/_base_collection.py | 48 ++++++++++++++++----------------- aeon/base/_base_series.py | 50 +++++++++++++++++------------------ aeon/base/_compose.py | 24 ++++++++--------- 4 files changed, 85 insertions(+), 83 deletions(-) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index 7a34de9ef1..539127aa26 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -1,4 +1,4 @@ -"""Base class template for ``aeon`` estimators.""" +"""Base class template for aeon estimators.""" __maintainer__ = ["MatthewMiddlehurst", "TonyBagnall"] __all__ = ["BaseAeonEstimator"] @@ -17,7 +17,7 @@ class BaseAeonEstimator(BaseEstimator, ABC): """ - Base class for defining estimators in ``aeon``. + Base class for defining estimators in aeon. Contains the following methods: @@ -25,16 +25,16 @@ class BaseAeonEstimator(BaseEstimator, ABC): - clone stimator (copy) - ``clone(random_state)`` - inspect tags (class method) - ``get_class_tags()`` - inspect tags (one tag, class) - ``get_class_tag(tag_name, tag_value_default - , raise_error)`` + , raise_error)`` - inspect tags (all) - ``get_tags()`` - inspect tags (one tag) - ``get_tag(tag_name, tag_value_default - , raise_error)`` + , raise_error)`` - setting dynamic tags - ``set_tags(**tag_dict)`` - get fitted parameters - ``get_fitted_params(deep)`` All estimators have the attribute: - - fitted state flag - `is_fitted` + - fitted state flag - ``is_fitted`` """ _tags = { @@ -60,21 +60,21 @@ def reset(self, keep=None): """ Reset the object to a clean post-init state. - After a ``self.reset()`` call, `self` is equal or similar in value to + After a ``self.reset()`` call, ``self`` is equal or similar in value to ``type(self)(**self.get_params(deep=False))``, assuming no other attributes - were kept using `keep`. + were kept using ``keep``. Detailed behaviour: removes any object attributes, except: hyper-parameters (arguments of ``__init__``) - object attributes containing double-underscores, i.e., the string `"__"` + object attributes containing double-underscores, i.e., the string ``__`` runs ``__init__`` with current values of hyperparameters (result of ``get_params``) Not affected by the reset are: object attributes containing double-underscores class and object methods, class attributes - any attributes specified in the `keep` argument + any attributes specified in the ``keep`` argument Parameters ---------- @@ -126,7 +126,7 @@ def clone(self, random_state=None): Obtain a clone of the object with the same hyperparameters. A clone is a different object without shared references, in post-init state. - This function is equivalent to returning ``sklearn.clone`` of `self`. + This function is equivalent to returning ``sklearn.clone`` of ``self``. Equal in value to ``type(self)(**self.get_params(deep=False))``. Parameters @@ -134,8 +134,10 @@ def clone(self, random_state=None): random_state : int, RandomState instance, or None, default=None Sets the random state of the clone. If ``None``, the random state is not set. - If ``int``, `random_state` is the seed used by the random number generator. - If ``RandomState`` instance, `random_state` is the random number generator. + If ``int``, ``random_state`` is the seed used by the random number + generator. + If ``RandomState`` instance, ``random_state`` is the random number + generator. Returns ------- @@ -294,7 +296,7 @@ def set_tags(self, **tag_dict): Returns ------- self : object - Reference to `self`. + Reference to ``self``. """ tag_update = deepcopy(tag_dict) self._tags_dynamic.update(tag_update) @@ -356,7 +358,7 @@ def _check_is_fitted(self): if not self.is_fitted: raise NotFittedError( f"This instance of {self.__class__.__name__} has not " - f"been fitted yet; please call `fit` first." + f"been fitted yet; please call ``fit`` first." ) @classmethod @@ -368,13 +370,13 @@ def _get_test_params(cls, parameter_set="default"): ---------- 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. + 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., + parameters to construct an ``interesting`` test instance, i.e., ``MyClass(**params)`` or ``MyClass(**params[i])`` creates a valid test instance. """ @@ -393,7 +395,7 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): ---------- 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. + special parameters are defined for a value, will return ``default`` set. return_first : bool, default=True If ``True``, return the first instance of the list of instances. If ``False``, return the list of instances. @@ -401,7 +403,7 @@ def _create_test_instance(cls, parameter_set="default", return_first=True): Returns ------- instance : BaseAeonEstimator or list of BaseAeonEstimator - Instance of the class with default parameters. If `return_first` + Instance of the class with default parameters. If ``return_first`` is ``False``, returns list of instances. """ params = cls._get_test_params(parameter_set=parameter_set) @@ -424,7 +426,7 @@ def __sklearn_is_fitted__(self): return self.is_fitted def __sklearn_tags__(self): - """Return ``sklearn`` style tags for the estimator.""" + """Return sklearn style tags for the estimator.""" aeon_tags = self.get_tags() sklearn_tags = super().__sklearn_tags__() sklearn_tags.non_deterministic = aeon_tags.get("non_deterministic", False) @@ -436,15 +438,15 @@ def __sklearn_tags__(self): return sklearn_tags def _validate_data(self, **kwargs): - """``Sklearn`` data validation.""" + """Sklearn data validation.""" raise NotImplementedError( "aeon estimators do not have a _validate_data method." ) def get_metadata_routing(self): - """``Sklearn`` metadata routing. + """Sklearn metadata routing. - Not supported by ``aeon`` estimators. + Not supported by aeon estimators. """ raise NotImplementedError( "aeon estimators do not have a get_metadata_routing method." diff --git a/aeon/base/_base_collection.py b/aeon/base/_base_collection.py index 98e69ed768..0b1c731043 100644 --- a/aeon/base/_base_collection.py +++ b/aeon/base/_base_collection.py @@ -14,7 +14,7 @@ class name: BaseCollectionEstimator fitted parameter inspection - ``get_fitted_params()`` State: - fitted model/strategy - by convention, any attributes ending in `"_"` + fitted model/strategy - by convention, any attributes ending in ``_`` fitted state flag - ``is_fitted (property)`` fitted state inspection - ``check_is_fitted()`` @@ -80,7 +80,7 @@ def _preprocess_collection(self, X, store_metadata=True): Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported data structures. store_metadata : bool, default=True Whether to store metadata about ``X`` in ``self.metadata_``. @@ -88,18 +88,18 @@ def _preprocess_collection(self, X, store_metadata=True): Returns ------- X : collection - Processed `X`. A data structure of type ``self.get_tag("X_inner_type")``. + Processed ``X``. A data structure of type ``self.get_tag("X_inner_type")``. Raises ------ ValueError - If `X` is an invalid type or has characteristics that the estimator cannot + If ``X`` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _check_X : - Function that checks `X` is valid before conversion. + Function that checks ``X`` is valid before conversion. _convert_X : Function that converts to inner type. @@ -138,39 +138,39 @@ def _check_X(self, X): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the capabilities of the estimator against the metadata - for `X` i.e., univariate/multivariate, equal length/unequal length + for ``X`` i.e., univariate/multivariate, equal length/unequal length and no missing values/missing values. Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported data structures. Returns ------- metadata : dict - Metadata about ``X``, with flags: - `metadata["multivariate"]` : whether `X` has more than one channel or + Metadata about ```X```, with flags: + ``metadata["multivariate"]`` : whether ``X`` has more than one channel or not - `metadata["missing_values"]` : whether `X` has missing values or not - `metadata["unequal_length"]` : whether `X` contains unequal length + ``metadata["missing_values"]`` : whether ``X`` has missing values or not + ``metadata["unequal_length"]`` : whether ``X`` contains unequal length series. - `metadata["n_cases"]` : number of cases in `X` - `metadata["n_channels"]` : number of channels in `X` - `metadata["n_timepoints"]` : number of timepoints in `X` if equal + ``metadata["n_cases"]`` : number of cases in ``X`` + ``metadata["n_channels"]`` : number of channels in ``X`` + ``metadata["n_timepoints"]`` : number of timepoints in ``X`` if equal length, else ``None`` Raises ------ ValueError - If `X` is an invalid type or has characteristics that the estimator cannot + If ``X`` is an invalid type or has characteristics that the estimator cannot handle. See Also -------- _convert_X : - Function that converts `X` after it has been checked. + Function that converts ``X`` after it has been checked. Examples -------- @@ -211,31 +211,31 @@ def _check_X(self, X): def _convert_X(self, X): """ - Convert `X` to type defined by tag ``X_inner_type``. + Convert ``X`` to type defined by tag ``X_inner_type``. If the input data is already an allowed type, it is returned unchanged. If multiple types are allowed by ``self``, then the best one for the type of input data is selected. So, for example, if - ``X_inner_tag`` is ["np-list", "numpy3D"] and an `df-list` is passed, it will - be converted to ``numpy3D`` if the series are equal length, and `np-list` + ``X_inner_tag`` is ["np-list", "numpy3D"] and an df-list is passed, it will + be converted to ``numpy3D`` if the series are equal length, and np-list if the series are unequal length. Parameters ---------- X : collection - See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on `aeon` supported + See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported data structures. Returns ------- X : collection - Converted `X`. A data structure of type ``self.get_tag("X_inner_type")``. + Converted ``X``. A data structure of type ``self.get_tag("X_inner_type")``. See Also -------- _check_X : - Function that checks `X` is valid and finds metadata. + Function that checks ``X`` is valid and finds metadata. Examples -------- @@ -278,7 +278,7 @@ def _convert_X(self, X): def _check_shape(self, X): """ - Check that the shape of `X` is consistent with the data seen in fit. + Check that the shape of ``X`` is consistent with the data seen in fit. Parameters ---------- @@ -288,7 +288,7 @@ def _check_shape(self, X): Raises ------ ValueError - If the shape of `X` is not consistent with the data seen in fit. + If the shape of ``X`` is not consistent with the data seen in fit. """ # if metadata is empty, then we have not seen any data in fit. If the estimator # has not been fitted, then _is_fitted should catch this. diff --git a/aeon/base/_base_series.py b/aeon/base/_base_series.py index 56af8fa874..07af84817b 100644 --- a/aeon/base/_base_series.py +++ b/aeon/base/_base_series.py @@ -34,25 +34,25 @@ class BaseSeriesEstimator(BaseAeonEstimator): It also stores the common default tags used by all the subclasses and meta data describing the characteristics of time series passed to ``fit``. - Input and internal data format (where `m` is the number of time points and `d` + Input and internal data format (where ``m`` is the number of time points and ``d`` is the number of channels): Univariate series: - np.ndarray, shape `(m,)`, `(m, 1)` or `(1, m)` depending on axis. + np.ndarray, shape ``(m,)``, ``(m, 1)`` or ``(1, m)`` depending on axis. This is converted to a 2D ``np.ndarray`` internally. - pd.DataFrame, shape `(m, 1)` or `(1, m)` depending on axis. - pd.Series, shape `(m,)` is converted to a ``pd.DataFrame``. + pd.DataFrame, shape ``(m, 1)`` or ``(1, m)`` depending on axis. + pd.Series, shape ``(m,)`` is converted to a ``pd.DataFrame``. Multivariate series: - ``np.ndarray`` array, shape `(m, d)` or `(d, m)` depending on axis. - ``pd.DataFrame`` `(m, d)` or `(d, m)` depending on axis. + ``np.ndarray`` array, shape ``(m, d)`` or ``(d, m)`` depending on axis. + ``pd.DataFrame`` ``(m, d)`` or ``(d, m)`` depending on axis. Parameters ---------- axis : int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels, n_timepoints)`. + ``(n_channels, n_timepoints)``. Setting this class variable will convert the input data to the chosen axis. """ @@ -70,10 +70,10 @@ def __init__(self, axis): super().__init__() def _preprocess_series(self, X, axis, store_metadata): - """Preprocess input `X` prior to call to fit. + """Preprocess input ``X`` prior to call to fit. - Checks the characteristics of `X`, store metadata, checks self can handle - the data then convert `X` to X_inner_type + Checks the characteristics of ``X``, store metadata, checks self can handle + the data then convert ``X`` to X_inner_type Parameters ---------- @@ -84,9 +84,9 @@ def _preprocess_series(self, X, axis, store_metadata): axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels, n_timepoints)`. + ``(n_channels, n_timepoints)``. store_metadata: bool If ``True``, overwrite metadata with the new metadata from X. @@ -106,7 +106,7 @@ def _check_X(self, X, axis): Check if the input data is a compatible type, and that this estimator is able to handle the data characteristics. This is done by matching the - capabilities of the estimator against the metadata for `X` for + capabilities of the estimator against the metadata for ``X`` for univariate/multivariate and no missing values/missing values. Parameters @@ -116,19 +116,19 @@ def _check_X(self, X, axis): ``aeon.base._base_series.VALID_SERIES_INPUT_TYPES`` for aeon supported types. axis: int - The time point axis of the input series if it is `2D`. If ``axis==0``, it is + The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints,n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints,n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels,n_timepoints)`. + ``(n_channels,n_timepoints)``. Returns ------- metadata: dict - Metadata about `X`, with flags: - ``metadata["multivariate"]``: whether `X` has more than one channel or not - ``metadata["n_channels"]``: number of channels in `X` - ``metadata["missing_values"]``: whether `X` has missing values or not + Metadata about ``X``, with flags: + ``metadata["multivariate"]``: whether ``X`` has more than one channel or not + ``metadata["n_channels"]``: number of channels in ``X`` + ``metadata["missing_values"]``: whether ``X`` has missing values or not """ if axis > 1 or axis < 0: raise ValueError(f"Input axis should be 0 or 1, saw {axis}") @@ -195,9 +195,9 @@ def _check_X(self, X, axis): return metadata def _convert_X(self, X, axis): - """Convert input `X` to internal estimator datatype. + """Convert input ``X`` to internal estimator datatype. - Converts input `X` to the internal data type of the estimator using + Converts input ``X`` to the internal data type of the estimator using ``self.get_tag("X_inner_type")``. 1D numpy arrays are converted to 2D, and the data will be transposed if the input axis does not match that of the estimator. @@ -214,9 +214,9 @@ def _convert_X(self, X, axis): axis: int The time point axis of the input series if it is 2D. If ``axis==0``, it is assumed each column is a time series and each row is a time point. i.e. the - shape of the data is `(n_timepoints, n_channels)`. ``axis==1`` indicates + shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates the time series are in rows, i.e. the shape of the data is - `(n_channels, n_timepoints)`. + ``(n_channels, n_timepoints)``. Returns ------- diff --git a/aeon/base/_compose.py b/aeon/base/_compose.py index a3b2021047..25e2fc7bfd 100644 --- a/aeon/base/_compose.py +++ b/aeon/base/_compose.py @@ -150,22 +150,22 @@ def _check_estimators( Parameters ---------- estimators : list - A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples. + A ``list`` of estimators or ``list`` of (``str``, ``estimator``) tuples. attr_name : str, optional. Default = "steps" Name of checked attribute in error messages class_type : class, tuple of class or None, default=BaseAeonEstimator. - Class(es) that all estimators in `estimators` are checked to be an + Class(es) that all estimators in ``estimators`` are checked to be an instance of. allow_tuples : boolean, default=True. - Whether tuples of (str, estimator) are allowed in `estimators`. + Whether tuples of (``str``, ``estimator``) are allowed in ``estimators``. Generally, the end-state we want is a ``list`` of tuples, so this should be ``True`` in most cases. allow_single_estimators : boolean, default=True. - Whether non-tuple estimator classes are allowed in `estimators`. + Whether non-tuple estimator classes are allowed in ``estimators``. unique_names : boolean, default=True. - Whether to check that all tuple strings in `estimators` are unique. + Whether to check that all tuple strings in ``estimators`` are unique. invalid_names : str, list of str or None, default=None. - Names that are invalid for estimators in `estimators`. + Names that are invalid for estimators in ``estimators``. Raises ------ @@ -233,24 +233,24 @@ def _check_estimators( def _convert_estimators(self, estimators, clone_estimators=True): """Convert estimators to list of (str, estimator) tuples. - Assumes ``_check_estimators`` has already been called on `estimators`. + Assumes ``_check_estimators`` has already been called on ``estimators``. Parameters ---------- estimators : list of estimators, or list of (str, estimator) tuples. - A ``list`` of estimators or ``list`` of (``str``, `estimator`) tuples + A ``list`` of estimators or ``list`` of (``str``, ``estimator``) tuples to be converted. clone_estimators : boolean, default=True. - Whether to return clone of estimators in `estimators` (``True``) or + Whether to return clone of estimators in ``estimators`` (``True``) or references (``False``). Returns ------- estimator_tuples : list of (str, estimator) tuples - If `estimators` was a ``list`` of (``str``, `estimator`) tuples, then + If ``estimators`` was a ``list`` of (``str``, ``estimator``) tuples, then identical/cloned - to `estimators`. - if was a ``list`` of `estimators` or mixed, then unique ``str`` + to ``estimators``. + if was a ``list`` of ``estimators`` or mixed, then unique ``str`` are generated to create tuples. """