ROCKET (RandOm Convolutional KErnel Transform) functions for univariate and multivariate time series.

generate_kernels[source]

generate_kernels(input_length, num_kernels, kss=[7, 9, 11], pad=True, dilate=True)

apply_kernel[source]

apply_kernel(X, weights, length, bias, dilation, padding)

apply_kernels[source]

apply_kernels(X, kernels)

class ROCKET[source]

ROCKET(c_in, seq_len, n_kernels=10000, kss=[7, 9, 11], device=None, verbose=False) :: Module

RandOm Convolutional KErnel Transform

ROCKET is a GPU Pytorch implementation of the ROCKET functions generate_kernels and apply_kernels that can be used with univariate and multivariate time series.

create_rocket_features[source]

create_rocket_features(dl, model, verbose=False)

Args: model : ROCKET model instance dl : single TSDataLoader (for example dls.train or dls.valid)

bs = 16
c_in = 7  # aka channels, features, variables, dimensions
c_out = 2
seq_len = 15
xb = torch.randn(bs, c_in, seq_len).to(default_device())

m = ROCKET(c_in, seq_len, n_kernels=1_000, kss=[7, 9, 11]) # 1_000 for testing with a cpu. Default is 10k with a gpu!
test_eq(m(xb).shape, [bs, 2_000])
from tsai.data.all import *
from tsai.models.utils import *
X, y, splits = get_UCR_data('OliveOil', split_data=False)
tfms = [None, TSRegression()]
batch_tfms = TSStandardize(by_var=True)
dls = get_ts_dls(X, y, splits=splits, tfms=tfms, batch_tfms=batch_tfms, shuffle_train=False, drop_last=False)
model = build_ts_model(ROCKET, dls=dls, n_kernels=1_000) # 1_000 for testing with a cpu. Default is 10k with a gpu!
X_train, y_train = create_rocket_features(dls.train, model) 
X_valid, y_valid = create_rocket_features(dls.valid, model)
X_train.shape, X_valid.shape
((30, 2000), (30, 2000))

class RocketClassifier[source]

RocketClassifier() :: Pipeline

Time series classification using ROCKET features and a linear classifier

load_rocket[source]

load_rocket(fname='Rocket', path='./models')

class RocketRegressor[source]

RocketRegressor() :: Pipeline

Time series regression using ROCKET features and a linear regressor

dsid = 'OliveOil'
fname = 'RocketClassifier'
X_train, y_train, X_test, y_test = get_UCR_data(dsid, Xdtype='float64')
cls = RocketClassifier()
cls.fit(X_train, y_train)
cls.save(fname)
del cls
cls = load_rocket(fname)
print(cls.score(X_test, y_test))
0.9
dsid = 'NATOPS'
fname = 'RocketClassifier'
X_train, y_train, X_test, y_test = get_UCR_data(dsid, Xdtype='float64')
cls = RocketClassifier()
cls.fit(X_train, y_train)
cls.save(fname)
del cls
cls = load_rocket(fname)
print(cls.score(X_test, y_test))
0.8833333333333333
from sklearn.metrics import mean_squared_error
dsid = 'Covid3Month'
fname = 'RocketRegressor'
X_train, y_train, X_test, y_test = get_Monash_data(dsid, Xdtype='float64')
rmse_scorer = make_scorer(mean_squared_error, greater_is_better=False)
reg = RocketRegressor(scoring=rmse_scorer)
reg.fit(X_train, y_train)
reg.save(fname)
del reg
reg = load_rocket(fname)
y_pred = reg.predict(X_test)
rmse = mean_squared_error(y_test, y_pred, squared=False)
rmse
0.04253489315496336
from sklearn.metrics import mean_squared_error
dsid = 'AppliancesEnergy'
fname = 'RocketRegressor'
X_train, y_train, X_test, y_test = get_Monash_data(dsid, Xdtype='float64')
rmse_scorer = make_scorer(mean_squared_error, greater_is_better=False)
reg = RocketRegressor(scoring=rmse_scorer)
reg.fit(X_train, y_train)
reg.save(fname)
del reg
reg = load_rocket(fname)
y_pred = reg.predict(X_test)
rmse = mean_squared_error(y_test, y_pred, squared=False)
rmse
2.4185885416566766