<jupyter_start><jupyter_text>MiniRocketMiniRocket transforms input time series using a small, fixed set of convolutional kernels.  MiniRocket uses PPV pooling to compute a single feature for each of the resulting feature maps (i.e., the proportion of positive values). The transformed features are used to train a linear classifier.<NAME>, <NAME>, <NAME> (2020) MiniRocket: A Very Fast (Almost) Deterministic Transform for Time Series Classification [arXiv:2012.08791](https://arxiv.org/abs/2012.08791)  1 Univariate Time Series 1.1 ImportsImport example data, MiniRocket, `RidgeClassifierCV` (scikit-learn), and NumPy.**Note**: MiniRocket and MiniRocketMultivariate are compiled by Numba on import.  The compiled functions are cached, so this should only happen once (i.e., the first time you import MiniRocket or MiniRocketMultivariate).<jupyter_code># !pip install --upgrade numba
import numpy as np
from sklearn.linear_model import RidgeClassifierCV
from sklearn.pipeline import make_pipeline

from sktime.datasets import load_arrow_head  # univariate dataset
from sktime.datasets import load_basic_motions  # multivariate dataset
from sktime.transformations.panel.rocket import MiniRocket, MiniRocketMultivariate<jupyter_output><empty_output><jupyter_text>1.2 Load the Training DataFor more details on the data set, see the [univariate time series classification notebook](https://github.com/alan-turing-institute/sktime/blob/main/examples/02_classification_univariate.ipynb).**Note**: Input time series must be *at least* of length 9.  Pad shorter time series using, e.g., `PaddingTransformer` (`sktime.transformers.panel.padder`).<jupyter_code>X_train, y_train = load_arrow_head(split="train", return_X_y=True)<jupyter_output><empty_output><jupyter_text>1.3 Initialise MiniRocket and Transform the Training Data<jupyter_code>minirocket = MiniRocket()  # by default, MiniRocket uses ~10,000 kernels
minirocket.fit(X_train)
X_train_transform = minirocket.transform(X_train)<jupyter_output><empty_output><jupyter_text>1.4 Fit a Classifier We suggest using `RidgeClassifierCV` (scikit-learn) for smaller datasets (fewer than ~10,000 training examples), and using logistic regression trained using stochastic gradient descent for larger datasets.**Note**: For larger datasets, this means integrating MiniRocket with stochastic gradient descent such that the transform is performed per minibatch, *not* simply substituting `RidgeClassifierCV` for, e.g., `LogisticRegression`.<jupyter_code>classifier = RidgeClassifierCV(alphas=np.logspace(-3, 3, 10), normalize=True)
classifier.fit(X_train_transform, y_train)<jupyter_output><empty_output><jupyter_text>1.5 Load and Transform the Test Data<jupyter_code>X_test, y_test = load_arrow_head(split="test", return_X_y=True)
X_test_transform = minirocket.transform(X_test)<jupyter_output><empty_output><jupyter_text>1.6 Classify the Test Data<jupyter_code>classifier.score(X_test_transform, y_test)<jupyter_output><empty_output><jupyter_text>*** 2 Multivariate Time SeriesWe can use the multivariate version of MiniRocket for multivariate time series input. 2.1 ImportsImport MiniRocketMultivariate.**Note**: MiniRocketMultivariate compiles via Numba on import.<jupyter_code># (above)<jupyter_output><empty_output><jupyter_text>2.2 Load the Training Data**Note**: Input time series must be *at least* of length 9.  Pad shorter time series using, e.g., `PaddingTransformer` (`sktime.transformers.panel.padder`).<jupyter_code>X_train, y_train = load_basic_motions(split="train", return_X_y=True)<jupyter_output><empty_output><jupyter_text>2.3 Initialise MiniRocket and Transform the Training Data<jupyter_code>minirocket_multi = MiniRocketMultivariate()
minirocket_multi.fit(X_train)
X_train_transform = minirocket_multi.transform(X_train)<jupyter_output><empty_output><jupyter_text>2.4 Fit a Classifier<jupyter_code>classifier = RidgeClassifierCV(alphas=np.logspace(-3, 3, 10), normalize=True)
classifier.fit(X_train_transform, y_train)<jupyter_output><empty_output><jupyter_text>2.5 Load and Transform the Test Data<jupyter_code>X_test, y_test = load_basic_motions(split="test", return_X_y=True)
X_test_transform = minirocket_multi.transform(X_test)<jupyter_output><empty_output><jupyter_text>2.6 Classify the Test Data<jupyter_code>classifier.score(X_test_transform, y_test)<jupyter_output><empty_output><jupyter_text>*** 3 Pipeline ExampleWe can use MiniRocket together with `RidgeClassifierCV` (or another classifier) in a pipeline.  We can then use the pipeline like a self-contained classifier, with a single call to `fit`, and without having to separately transform the data, etc. 3.1 Imports<jupyter_code># (above)<jupyter_output><empty_output><jupyter_text>3.2 Initialise the Pipeline<jupyter_code>minirocket_pipeline = make_pipeline(
    MiniRocket(), RidgeClassifierCV(alphas=np.logspace(-3, 3, 10), normalize=True)
)<jupyter_output><empty_output><jupyter_text>3.3 Load and Fit the Training Data**Note**: Input time series must be *at least* of length 9.  Pad shorter time series using, e.g., `PaddingTransformer` (`sktime.transformers.panel.padder`).<jupyter_code>X_train, y_train = load_arrow_head(split="train")

# it is necessary to pass y_train to the pipeline
# y_train is not used for the transform, but it is used by the classifier
minirocket_pipeline.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>3.4 Load and Classify the Test Data<jupyter_code>X_test, y_test = load_arrow_head(split="test")

minirocket_pipeline.score(X_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09249909844933285, 'fraction_numerical': 0.015146051208077894, 'mean_word_length': 8.09344262295082, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 68, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '285478', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1748, 'n_words': 467, 'path': 'examples/minirocket.ipynb', 'repo_name': 'benHeid/sktime', 'size': '5555'}