Docs /Templates/ sinapsis-sktime

ShapeDTWSKTimeWrapper

sinapsis-sktimeSKTimedynamicinferencemodelsprediction

Python template · sinapsis_sktime.templates.sktime_classifiers

Overview

Template for SkTime classification model training and inference for the distance_based module.

ShapeDTW — inherited documentation

ShapeDTW classifier.

ShapeDTW[1] works by initially extracting a set of subsequences describing local neighbourhoods around each data point in a time series. These subsequences are then passed into a shape descriptor function that transforms these local neighbourhoods into a new representation. This new representation is then sent into DTW with 1-NN.

Parameters ---------- n_neighbors : int, int, set k for knn (default =1). subsequence_length : int, defines the length of the subsequences(default=sqrt(n_timepoints)).

shape_descriptor_function : string, defines the function to describe the set of subsequences (default = 'raw').

The possible shape descriptor functions are as follows:

- 'raw' : use the raw subsequence as the shape descriptor function. - params = None

- 'paa' : use PAA as the shape descriptor function. - params = num_intervals_paa (default=8)

- 'dwt' : use DWT (Discrete Wavelet Transform) as the shape descriptor function. - params = num_levels_dwt (default=3)

- 'slope' : use the gradient of each subsequence fitted by a total least squares regression as the shape descriptor function. - params = num_intervals_slope (default=8)

- 'derivative' : use the derivative of each subsequence as the shape descriptor function. - params = None

- 'hog1d' : use a histogram of gradients in one dimension as the shape descriptor function. - params = num_intervals_hog1d (default=2) = num_bins_hod1d (default=8) = scaling_factor_hog1d (default=0.1)

- 'compound' : use a combination of two shape descriptors simultaneously. - params = weighting_factor (default=None) Defines how to scale values of a shape descriptor. If a value is not given, this value is tuned by 10-fold cross-validation on the training data.

shape_descriptor_functions : string list, only applicable when the shape_descriptor_function is set to 'compound'. Use a list of shape descriptor functions at the same time. (default = ['raw','derivative'])

metric_params : dictionary for metric parameters (default = None).

n_splits : int, number of splits for cross-validation (default = 10). Used for finding the weighting_factor if 'shape_descriptor_function' is set to 'compound' and weighting_factor is not given in 'metric_params'.

Notes ----- .. [1] Jiaping Zhao and Laurent Itti, "shapeDTW: Shape Dynamic Time Warping", Pattern Recognition, 74, pp 171-184, 2018 http://www.sciencedirect.com/science/article/pii/S0031320317303710,

Examples -------- >>> from sktime.classification.distance_based import ShapeDTW >>> from sktime.datasets import load_unit_test # doctest: +SKIP >>> X_train, y_train = load_unit_test(split="train") # doctest: +SKIP >>> X_test, y_test = load_unit_test(split="test") # doctest: +SKIP >>> clf = ShapeDTW(n_neighbors=1, ... subsequence_length=30, ... shape_descriptor_function="raw", ... shape_descriptor_functions=None, ... metric_params=None, ... ) # doctest: +SKIP >>> clf.fit(X_train, y_train) # doctest: +SKIP ShapeDTW(...) >>> y_pred = clf.predict(X_test) # doctest: +SKIP

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-sktime==1.0.0
uv pip install sinapsis-sktime==1.0.0
uv add sinapsis-sktime==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
root_dir
str
Optional
Default: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
shapedtw_initRequired
ShapeDTWAttributes
Required
Default: null
n_splits
int
Optional
Default: 10
n_neighbors
int
Optional
Default: 1
metric_params
NoneType
Optional
Default: null
subsequence_length
int
Optional
Default: 30
shape_descriptor_function
str
Optional
Default: "raw"
shape_descriptor_functions
NoneType
Optional
Default: null
model_save_pathRequired
Path where the trained model will be saved. shapedtw_init n_neighbors <class 'int'>: default: 1 subsequence_length <class 'int'>: default: 30 shape_descriptor_function <class 'str'>: default: raw… Read full field description

Path where the trained model will be saved. shapedtw_init n_neighbors <class 'int'>: default: 1 subsequence_length <class 'int'>: default: 30 shape_descriptor_function <class 'str'>: default: raw shape_descriptor_functions <class 'NoneType'>: default: None metric_params <class 'NoneType'>: default: None n_splits <class 'int'>: default: 10

str
Required
Default: null

Configuration example

Generated from documented defaults. Replace any placeholders and complete required nested settings before running.

yaml
templates:
  - template_name: "ShapeDTWSKTimeWrapper"
    class_name: "ShapeDTWSKTimeWrapper"
    attributes:
      root_dir: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
      shapedtw_init:
        n_splits: 10
        n_neighbors: 1
        metric_params: null
        subsequence_length: 30
        shape_descriptor_function: "raw"
        shape_descriptor_functions: null
      model_save_path: "<required>"

Inheritance

Immediate parent: sinapsis_sktime.templates.sktime_classifiers.SKTimeDistanceClassifiers

Environment variables

Environment definitions belong to their canonical Python modules.

SINAPSIS_BUILD_DOCS · defined elsewhere