ROCKET

class hana_ml.algorithms.pal.tsa.rocket.ROCKET(method=None, num_features=None, data_dim=None, random_seed=None)

RandOm Convolutional KErnel Transform (ROCKET) is an exceptionally efficient algorithm for time series classification. Unlike other proposed time series classification algorithms which attain excellent accuracy, ROCKET maintains its performance with a fraction of the computational expense by transforming input time series using random convolutional kernels.

Parameters:
methodstr, optional

The options are "MiniRocket" and "MultiRocket".

Defaults to "MiniRocket".

num_featuresint, optional

Number of transformed features for each time series.

Defaults to 9996 when method = "MiniRocket", 49728 when method = "MultiRocket".

data_dimint, optional

Dimensionality of the multivariate time series.

1 means univariate time series and others for multivariate. Cannot be smaller than 1.

Defaults to 1.

random_seedint, optional

0 indicates using machine time as seed.

Defaults to 0.

Examples

Example 1: Univariate time series fitted and transformed by MiniRocket Input DataFrame df:

>>> df.collect()
    RECORD_ID  VAL_1  VAL_2  VAL_3  VAL_4  VAL_5  VAL_6  ...  VAL_10  VAL_11  VAL_12  VAL_13  VAL_14  VAL_15  VAL_16
0           0  1.598  1.599  1.571  1.550  1.507  1.434  ...   1.117   1.024   0.926   0.828   0.739   0.643   0.556
1           1  1.701  1.671  1.619  1.547  1.475  1.391  ...   1.070   0.985   0.899   0.816   0.733   0.658   0.581
...
10         10  1.614  1.574  1.557  1.521  1.460  1.406  ...   1.045   0.957   0.862   0.771   0.681   0.587   0.497
11         11  1.652  1.665  1.656  1.623  1.571  1.499  ...   1.155   1.058   0.973   0.877   0.797   0.704   0.609

Create an instance of ROCKET:

>>> ro = ROCKET(method="MiniRocket", random_seed=1)

Perform fit():

>>> ro.fit(data=df)

Model:

>>> ro.model_.collect()
    ID                                      MODEL_CONTENT
0   -1                                         MiniRocket
1    0  {"SERIES_LENGTH":16,"NUM_CHANNELS":1,"BIAS_SIZ...
2    1  843045766098464,1.0396523357230486,2.005001093...
......

Make a transformation:

>>> result = ro.transform(data=df)
>>> result.collect()
      ID                                     STRING_CONTENT
0      0  {"NUM_FEATURES_PER_DATA":9996,"FEATURES":[{"DA...
1      1  ,0.375,0.875,0.125,0.5,1.0,0.25,0.75,1.0,0.375...
...
126  126  .0,0.0,0.75,0.0,0.375,1.0,0.0,0.75,1.0,0.125,0...
127  127  25,0.625,0.1875,0.375,0.75,0.0,0.625,0.0,0.0,0...

Example 2: Multivariate time series (with dimensionality 8) fitted and transformed by MultiRocket Input DataFrame df:

>>> df.collect()
    RECORD_ID  VAL_1  VAL_2  VAL_3  VAL_4  VAL_5  VAL_6  ...  VAL_10  VAL_11  VAL_12  VAL_13  VAL_14  VAL_15  VAL_16
0           0  1.645  1.646  1.621  1.585  1.540  1.470  ...   1.161   1.070   0.980   0.893   0.798   0.705   0.620
1           1  1.704  1.705  1.706  1.680  1.632  1.560  ...   1.186   1.090   0.994   0.895   0.799   0.702   0.605
...
30         30  1.688  1.648  1.570  1.490  1.408  1.327  ...   1.011   0.930   0.849   0.768   0.687   0.606   0.524
31         31  1.708  1.663  1.595  1.504  1.411  1.318  ...   0.951   0.861   0.794   0.704   0.614   0.529   0.446

Create an instance of ROCKET:

>>> ro = ROCKET(method="multirocket", data_dim=8)

Perform fit():

>>> ro.fit(data=df)

Model:

>>> ro.model_.collect()
    ID                                      MODEL_CONTENT
0   -1                                        MultiRocket
1    0  {"SERIES_LENGTH":16,"NUM_CHANNELS":8,"BIAS_SIZ...
2    1  HANNELS":[6]},{"ID":77,"CHANNELS":[1,4,7,6,5]}...
......

Make a transformation:

>>> result = ro.transform(data=df)
>>> result.collect()
      ID                                     STRING_CONTENT
0      0  {"NUM_FEATURES_PER_DATA":49728,"FEATURES":[{"D...
1      1  .5625,0.8125,0.125,0.6875,0.9375,0.5,0.6875,0....
..   ...                                                ...
241  241  .857142,7.357142,12.333333,9.0,12.5,11.8,7.692...
242  242  1.0,3.0,3.0,5.0,3.0,-1.0,3.0,3.0,-1.0,3.0,-1.0...
Attributes:
model_DataFrame

Model content.

Methods

fit(data[, key])

Fit the model to the training dataset.

get_model_metrics()

Get the model metrics.

get_score_metrics()

Get the score metrics.

transform(data[, key, thread_ratio])

Transform time series based on a given ROCKET model fitted by fit().

fit(data, key=None)

Fit the model to the training dataset.

Parameters:
dataDataFrame

Input data.

For univariate time series, each row represents one time series, while for multivariate time series, a fixed number of consecutive rows forms one time series, and that number is designated by the parameter data_dim when initialize a ROCKET instance.

keystr, optional

The ID column.

Defaults to the first column of data if the index column of data is not provided. Otherwise, defaults to the index column of data.

Returns:
A fitted object of class "ROCKET".
transform(data, key=None, thread_ratio=None)

Transform time series based on a given ROCKET model fitted by fit(). Hence, The data should be in the exact same format as that in fit(), especially the length and dimensionality of time series. The model_ used in transform comes from fit() as well.

Parameters:
dataDataFrame

Input data. For univariate time series, each row represents one time series, while for multivariate time series, a fixed number of consecutive rows forms one time series, and that number is designated by the parameter data_dim when initialize a ROCKET instance.

keystr, optional

The ID column.

Defaults to the first column of data if the index column of data is not provided. Otherwise, defaults to the index column of data.

thread_ratiofloat, optional

Adjusts the percentage of available threads to use, from 0 to 1. A value of 0 indicates the use of a single thread, while 1 implies the use of all possible current threads. Values outside the range will be ignored and this function heuristically determines the number of threads to use.

Defaults to 1.0.

Returns:
DataFrame

Features, structured as follows:

  • ID, type INTEGER, ROW_INDEX, indicates the ID of current row.

  • STRING_CONTENT, type NVARCHAR, transformed features in JSON format.

get_model_metrics()

Get the model metrics.

Returns:
DataFrame

The model metrics.

get_score_metrics()

Get the score metrics.

Returns:
DataFrame

The score metrics.

Inherited Methods from PALBase

Besides those methods mentioned above, the ROCKET class also inherits methods from PALBase class, please refer to PAL Base for more details.