Skip to content

Rocket

polars_ts.features.rocket

ROCKET and MiniRocket feature extraction for time series.

Transforms each time series into a fixed-length feature vector using random convolutional kernels, enabling fast and accurate clustering/classification in the resulting feature space.

References

  • Dempster et al. (2020) ROCKET: Exceptionally fast and accurate time series classification using random convolutional kernels. DMKD.
  • Dempster et al. (2021) MiniRocket: A very fast (almost) deterministic transform for time series classification. KDD.

_extract_series(df, target_col, id_col, time_col)

Extract series as a 2-D array (n_series, max_len), zero-padded.

_generate_rocket_kernels(n_kernels, input_length, rng)

Generate random convolutional kernels for ROCKET.

Returns list of (weights, bias, dilation) tuples.

_apply_kernel(x, weights, bias, dilation)

Apply a single kernel to a 1-D series, return (ppv, max_val).

rocket_features(df, n_kernels=500, target_col='y', id_col='unique_id', time_col='ds', seed=42)

Extract ROCKET features from time series.

Generates n_kernels random convolutional kernels with varying length, dilation, and bias, then computes PPV (proportion of positive values) and global max for each kernel on every series.

Parameters

df Input DataFrame with time series data. n_kernels Number of random convolutional kernels. target_col Column with the values to transform. id_col Column identifying each time series. time_col Column with timestamps for ordering. seed Random seed for reproducibility.

Returns

pl.DataFrame DataFrame with columns [id_col, rocket_0, rocket_1, ..., rocket_{2*n_kernels - 1}].

_get_minirocket_patterns()

Return the 84 fixed MiniRocket weight patterns.

Uses the 84 unique patterns from C(9,3) = 84 combinations. Each pattern has weights of 2 at selected positions and -1 elsewhere, then mean-centered.

_compute_dilations(input_length, n_dilations)

Compute dilations ensuring the kernel spans the full input length.

minirocket_features(df, n_kernels=500, target_col='y', id_col='unique_id', time_col='ds', seed=42)

Extract MiniRocket features from time series.

Uses fixed-length (9) kernels with deterministic weight patterns and learned biases. Significantly faster than ROCKET while achieving comparable accuracy.

Parameters

df Input DataFrame with time series data. n_kernels Approximate number of kernels (rounded to nearest multiple of 84). target_col Column with the values to transform. id_col Column identifying each time series. time_col Column with timestamps for ordering. seed Random seed for bias sampling.

Returns

pl.DataFrame DataFrame with columns [id_col, minirocket_0, ..., minirocket_{n_features - 1}].

_convolve_1d(x, weights, dilation)

1-D dilated convolution (no bias) returning the raw output.