Skip to content

RandomShapeletTransform

RandomShapeletTransform

class RandomShapeletTransform(n_shapelet_samples=10000, max_shapelets=None, min_shapelet_length=3, max_shapelet_length=None, remove_self_similar=True, time_limit_in_minutes=0.0, contract_max_n_shapelet_samples=inf, n_jobs=1, parallel_backend=None, batch_size=100, random_state=None)[source]

Random Shapelet Transform.

Implementation of the binary shapelet transform along the lines of [R23aa2a61a9f8-1]_[R23aa2a61a9f8-2]_, with randomly extracted shapelets.

Overview: Input “n” series with “d” dimensions of length “m”. Continuously extract candidate shapelets and filter them in batches. For each candidate shapelet

  • Extract a shapelet from an instance with random length, position and

    dimension

  • Using its distance to train cases, calculate the shapelets information

    gain

  • Abandon evaluating the shapelet if it is impossible to obtain a higher

    information gain than the current worst

For each shapelet batch

  • Add each candidate to its classes shapelet heap, removing the lowest

    information gain shapelet if the max number of shapelets has been met

  • Remove self-similar shapelets from the heap

Using the final set of filtered shapelets, transform the data into a vector of of distances from a series to each shapelet.

Parameters:
n_shapelet_samplesint, default=10000

The number of candidate shapelets to be considered for the final transform. Filtered down to <= max_shapelets, keeping the shapelets with the most information gain.

max_shapeletsint or None, default=None

Max number of shapelets to keep for the final transform. Each class value will have its own max, set to n_classes / max_shapelets. If None uses the min between 10 * n_instances and 1000

min_shapelet_lengthint, default=3

Lower bound on candidate shapelet lengths.

max_shapelet_lengthint or None, default= None

Upper bound on candidate shapelet lengths. If None no max length is used.

remove_self_similarboolean, default=True

Remove overlapping “self-similar” shapelets when merging candidate shapelets.

time_limit_in_minutesint, default=0

Time contract to limit build time in minutes, overriding n_shapelet_samples. Default of 0 means n_shapelet_samples is used.

contract_max_n_shapelet_samplesint, default=np.inf

Max number of shapelets to extract when time_limit_in_minutes is set.

n_jobsint, default=1

The number of jobs to run in parallel for both fit and transform. -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.

batch_sizeint or None, default=100

Number of shapelet candidates processed before being merged into the set of best shapelets.

random_stateint or None, default=None

Seed for random number generation.

Attributes:
n_classesint

The number of classes.

n_instancesint

The number of train cases.

n_dimsint

The number of dimensions per case.

series_lengthint

The length of each series.

classes_list

The classes labels.

shapeletslist

The stored shapelets and relating information after a dataset has been processed. Each item in the list is a tuple containing the following 7 items: (shapelet information gain, shapelet length, start position the shapelet was extracted from, shapelet dimension, index of the instance the shapelet was extracted from in fit, class value of the shapelet, The z-normalised shapelet array)

See also

ShapeletTransformClassifier

Notes

For the Java version, see TSML.

References

[1]

Jon Hills et al., “Classification of time series by shapelet transformation”, Data Mining and Knowledge Discovery, 28(4), 851–881, 2014.

[2]

A. Bostrom and A. Bagnall, “Binary Shapelet Transform for Multiclass Time Series Classification”, Transactions on Large-Scale Data and Knowledge Centered Systems, 32, 2017.

Examples

>>> from sktime.transformations.shapelet_transform import (
...     RandomShapeletTransform
... )
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train", return_X_y=True)
>>> t = RandomShapeletTransform(
...     n_shapelet_samples=500,
...     max_shapelets=10,
...     batch_size=100,
... )
>>> t.fit(X_train, y_train)
RandomShapeletTransform(...)
>>> X_t = t.transform(X_train)

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X[, y])

Fit transformer to X, optionally to y.

fit_transform(X[, y])

Fit to data, then transform it.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

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

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

inverse_transform(X[, y])

Inverse transform X and return an inverse transformed version.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

transform(X[, y])

Transform X and return a transformed version.

update(X[, y, update_params])

Update transformer with X, optionally y.