SupervisedIntervals

class SupervisedIntervals(n_intervals=50, min_interval_length=3, features=None, metric='fisher', randomised_split_point=True, normalise_for_search=True, random_state=None, n_jobs=1, parallel_backend=None)[source]

Supervised interval feature transformer.

Extracts intervals in fit using the supervised process described in [1]. Interval subseries are extracted for each input feature, and the usefulness of that feature extracted on an interval is evaluated using the Fisher score metric. Intervals are continually split in half, with the better scoring half retained as a feature for the transform.

Multivariate capability is added by running the supervised interval extraction process on each dimension of the input data.

As the interval features are already extracted for the supervised evaluation in fit, the fit_transform method is recommended if the transformed fit data is required.

Parameters:
n_intervalsint, default=50

The number of times the supervised interval selection process is run. Each supervised extraction will output a varying amount of features based on series length, number of dimensions and the number of features.

min_interval_lengthint, default=3

The minimum length of extracted intervals. Minimum value of 3.

featurescallable, list of callables, default=None

Functions used to extract features from selected intervals. Must take a 2d array of shape (n_cases, interval_length) and return a 1d array of shape (n_cases) containing the features. If None, defaults to the following statistics used in [2]: [mean, median, std, slope, min, max, iqr, count_mean_crossing, count_above_mean].

metric[“fisher”] or callable, default=”fisher”

The metric used to evaluate the usefulness of a feature extracted on an interval. If “fisher”, the Fisher score is used. If a callable, it must take a 1d array of shape (n_cases) and return a 1d array of scores of shape (n_cases).

randomised_split_pointbool, default=True

If True, the split point for interval extraction is randomised as is done in [2] rather than split in half.

normalise_for_searchbool, default=True

If True, the data is normalised for the supervised interval search process. Features extracted for the transform output will not use normalised data.

random_stateNone, int or instance of RandomState, default=None

Seed or RandomState object used for random number generation. If random_state is None, use the RandomState singleton used by np.random. If random_state is an int, use a new RandomState instance seeded with seed.

n_jobsint, default=1

The number of jobs to run in parallel for both fit and transform functions. -1 means using all processors.

parallel_backendstr, ParallelBackendBase instance or None, default=None

Specify the parallelisation backend implementation in joblib, if None a ‘prefer’ value of “threads” is used by default. Valid options are “loky”, “multiprocessing”, “threading” or a custom backend. See the joblib Parallel documentation for more details.

Attributes:
n_cases_int

The number of train cases.

n_channels_int

The number of dimensions per case.

n_timepoints_int

The length of each series.

intervals_list of tuples

Contains information for each feature extracted in fit. Each tuple contains the interval start, interval end, interval dimension and the feature extracted. Length will be the same as the amount of transformed features.

See also

RandomIntervals

Notes

Based on the authors (stevcabello) code: https://github.com/stevcabello/r-STSF/

References

[1]

Cabello, N., Naghizade, E., Qi, J. and Kulik, L., 2020, November. Fast and accurate time series classification through supervised interval search. In 2020 IEEE International Conference on Data Mining (ICDM) (pp. 948-953). IEEE.

[2]

Cabello, N., Naghizade, E., Qi, J. and Kulik, L., 2021. Fast, accurate and interpretable time series classification through randomization. arXiv preprint arXiv:2105.14876.

Examples

>>> from aeon.transformations.collection.interval_based import SupervisedIntervals
>>> from aeon.testing.data_generation import make_example_3d_numpy
>>> X, y = make_example_3d_numpy(n_cases=10, n_channels=1, n_timepoints=20,
...                              random_state=0)
>>> tnf = SupervisedIntervals(n_intervals=1, random_state=0)
>>> tnf.fit(X, y)
SupervisedIntervals(...)
>>> print(tnf.transform(X)[0])
[ 1.30432257  1.52868198  1.25050357  1.20552675  0.52110404  0.64603743
  0.23156024 -0.45946127  0.14207212  1.05778984  1.43037873  1.85119328
  1.32237758  0.70689282  0.39670172  1.          2.          2.        ]

Methods

clone([random_state])

Obtain a clone of the object with the same hyperparameters.

fit(X[, y])

Fit transformer to X, optionally using y if supervised.

fit_transform(X[, y])

Fit to data, then transform it.

get_class_tag(tag_name[, raise_error, ...])

Get tag value from estimator class (only class tags).

get_class_tags()

Get class tags from estimator class and all its parent classes.

get_fitted_params([deep])

Get fitted parameters.

get_metadata_routing()

Sklearn metadata routing.

get_params([deep])

Get parameters for this estimator.

get_tag(tag_name[, raise_error, ...])

Get tag value from estimator class.

get_tags()

Get tags from estimator.

inverse_transform(X[, y])

Inverse transform X and return an inverse transformed version.

reset([keep])

Reset the object to a clean post-init state.

set_features_to_transform(arr[, raise_error])

Set transform_features to the given array.

set_params(**params)

Set the parameters of this estimator.

set_tags(**tag_dict)

Set dynamic tags to given values.

transform(X[, y])

Transform X and return a transformed version.

set_features_to_transform(arr, raise_error=True)[source]

Set transform_features to the given array.

Each index in the list corresponds to the index of an interval, True intervals are included in the transform, False intervals skipped and are set to 0.

Parameters:
arrlist of bools

A list of intervals to skip.

raise_errorbool, default=True

Whether to raise and error or return None if input is invalid.

Returns:
completed: bool

Whether the operation was successful.

clone(random_state=None)[source]

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. Equal in value to type(self)(**self.get_params(deep=False)).

Parameters:
random_stateint, 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.

Returns:
estimatorobject

Instance of type(self), clone of self (see above)

fit(X, y=None)[source]

Fit transformer to X, optionally using y if supervised.

State change:

Changes state to “fitted”.

Writes to self: _is_fitted : flag is set to True. model attributes (ending in “_”) : dependent on estimator

Parameters:
Xnp.ndarray or list

Input data, any number of channels, equal length series of shape ( n_cases, n_channels, n_timepoints) or list of numpy arrays (any number of channels, unequal length series) of shape [n_cases], 2D np.array (n_channels, n_timepoints_i), where n_timepoints_i is length of series i. Other types are allowed and converted into one of the above.

Different estimators have different capabilities to handle different types of input. If self.get_tag(“capability:multivariate”)` is False, they cannot handle multivariate series. If self.get_tag( "capability:unequal_length") is False, they cannot handle unequal length input. In both situations, a ValueError is raised if X has a characteristic that the estimator does not have the capability to handle.

Data to fit transform to, of valid collection type.

ynp.ndarray, default=None

1D np.array of float or str, of shape (n_cases) - class labels (ground truth) for fitting indices corresponding to instance indices in X. If None, no labels are used in fitting.

Returns:
selfa fitted instance of the estimator
fit_transform(X, y=None)[source]

Fit to data, then transform it.

Fits the transformer to X and y and returns a transformed version of X.

State change:

Changes state to “fitted”.

Writes to self: _is_fitted : flag is set to True. model attributes (ending in “_”) : dependent on estimator.

Parameters:
Xnp.ndarray or list

Input data, any number of channels, equal length series of shape ( n_cases, n_channels, n_timepoints) or list of numpy arrays (any number of channels, unequal length series) of shape [n_cases], 2D np.array (n_channels, n_timepoints_i), where n_timepoints_i is length of series i. Other types are allowed and converted into one of the above.

Different estimators have different capabilities to handle different types of input. If self.get_tag(“capability:multivariate”)` is False, they cannot handle multivariate series. If self.get_tag( "capability:unequal_length") is False, they cannot handle unequal length input. In both situations, a ValueError is raised if X has a characteristic that the estimator does not have the capability to handle.

Data to fit transform to, of valid collection type.

ynp.ndarray, default=None

1D np.array of float or str, of shape (n_cases) - class labels (ground truth) for fitting indices corresponding to instance indices in X. If None, no labels are used in fitting.

Returns:
transformed version of X
classmethod get_class_tag(tag_name, raise_error=True, tag_value_default=None)[source]

Get tag value from estimator class (only class tags).

Parameters:
tag_namestr

Name of tag value.

raise_errorbool, default=True

Whether a ValueError is raised when the tag is not found.

tag_value_defaultany type, default=None

Default/fallback value if tag is not found and error is not raised.

Returns:
tag_value

Value of the tag_name tag in cls. 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 self.get_tags().keys()

Examples

>>> from aeon.classification import DummyClassifier
>>> DummyClassifier.get_class_tag("capability:multivariate")
True
classmethod get_class_tags()[source]

Get class tags from estimator class and all its parent classes.

Returns:
collected_tagsdict

Dictionary of tag name and tag value pairs. Collected from _tags class attribute via nested inheritance. These are not overridden by dynamic tags set by set_tags or class __init__ calls.

get_fitted_params(deep=True)[source]

Get fitted parameters.

State required:

Requires state to be “fitted”.

Parameters:
deepbool, default=True

If True, will return the fitted parameters for this estimator and contained subobjects that are estimators.

Returns:
fitted_paramsdict

Fitted parameter names mapped to their values.

get_metadata_routing()[source]

Sklearn metadata routing.

Not supported by aeon estimators.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_tag(tag_name, raise_error=True, tag_value_default=None)[source]

Get tag value from estimator class.

Includes dynamic and overridden tags.

Parameters:
tag_namestr

Name of tag to be retrieved.

raise_errorbool, default=True

Whether a ValueError is raised when the tag is not found.

tag_value_defaultany type, default=None

Default/fallback value if tag is not found and error is not raised.

Returns:
tag_value

Value of the tag_name tag in self. 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 self.get_tags().keys()

Examples

>>> from aeon.classification import DummyClassifier
>>> d = DummyClassifier()
>>> d.get_tag("capability:multivariate")
True
get_tags()[source]

Get tags from estimator.

Includes dynamic and overridden tags.

Returns:
collected_tagsdict

Dictionary of tag name and tag value pairs. Collected from _tags class attribute via nested inheritance and then any overridden and new tags from __init__ or set_tags.

inverse_transform(X, y=None)[source]

Inverse transform X and return an inverse transformed version.

Currently it is assumed that only transformers with tags

“input_data_type”=”Series”, “output_data_type”=”Series”,

can have an inverse_transform.

State required:

Requires state to be “fitted”.

Accesses in self:

_is_fitted : must be True fitted model attributes (ending in “_”) : accessed by _inverse_transform

Parameters:
Xnp.ndarray or list

Input data, any number of channels, equal length series of shape ( n_cases, n_channels, n_timepoints) or list of numpy arrays (any number of channels, unequal length series) of shape [n_cases], 2D np.array (n_channels, n_timepoints_i), where n_timepoints_i is length of series i. Other types are allowed and converted into one of the above.

Different estimators have different capabilities to handle different types of input. If self.get_tag(“capability:multivariate”)` is False, they cannot handle multivariate series. If self.get_tag( "capability:unequal_length") is False, they cannot handle unequal length input. In both situations, a ValueError is raised if X has a characteristic that the estimator does not have the capability to handle.

Data to fit transform to, of valid collection type.

ynp.ndarray, default=None

1D np.array of float or str, of shape (n_cases) - class labels (ground truth) for fitting indices corresponding to instance indices in X. If None, no labels are used in fitting.

Returns:
inverse transformed version of X

of the same type as X

reset(keep=None)[source]

Reset the object to a clean post-init state.

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.

Detailed behaviour:
removes any object attributes, except:

hyper-parameters (arguments of __init__) 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

Parameters:
keepNone, 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.

Returns:
selfobject

Reference to self.

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_tags(**tag_dict)[source]

Set dynamic tags to given values.

Parameters:
**tag_dictdict

Dictionary of tag name and tag value pairs.

Returns:
selfobject

Reference to self.

transform(X, y=None)[source]

Transform X and return a transformed version.

State required:

Requires state to be “fitted”.

Accesses in self: _is_fitted : must be True fitted model attributes (ending in “_”) : must be set, accessed by _transform

Parameters:
Xnp.ndarray or list

Input data, any number of channels, equal length series of shape ( n_cases, n_channels, n_timepoints) or list of numpy arrays (any number of channels, unequal length series) of shape [n_cases], 2D np.array (n_channels, n_timepoints_i), where n_timepoints_i is length of series i. Other types are allowed and converted into one of the above.

Different estimators have different capabilities to handle different types of input. If self.get_tag(“capability:multivariate”)` is False, they cannot handle multivariate series. If self.get_tag( "capability:unequal_length") is False, they cannot handle unequal length input. In both situations, a ValueError is raised if X has a characteristic that the estimator does not have the capability to handle.

Data to fit transform to, of valid collection type.

ynp.ndarray, default=None

1D np.array of float or str, of shape (n_cases) - class labels (ground truth) for fitting indices corresponding to instance indices in X. If None, no labels are used in fitting.

Returns:
transformed version of X