<jupyter_start><jupyter_text>The Canonical Time-series Characteristics (catch22) transformcatch22\[1\] is a collection of 22 time series features extracted from the 7000+ present in the _hctsa_ \[2\]\[3\] toolbox.A hierarchical clustering was performed on the correlation matrix of features that performed better than random chance to remove redundancy.These clusters were sorted by balanced accuracy using a decision tree classifier and a single feature was selected from the 22 clusters formed, taking into account balanced accuracy results, computational efficiency and interpretability.In this notebook, we will demonstrate how to use the catch22 transformer on the ItalyPowerDemand univariate and BasicMotions multivariate datasets. We also show catch22 used for classification with a random forest classifier. References:\[1\] <NAME>., <NAME>., <NAME>., <NAME>., <NAME>., & <NAME>. (2019). catch22: CAnonical Time-series CHaracteristics. Data Mining and Knowledge Discovery, 33(6), 1821-1852.\[2\] <NAME>., & <NAME>. (2017). hctsa: A computational framework for automated time-series phenotyping using massive feature extraction. Cell systems, 5(5), 527-531.\[3\] <NAME>., <NAME>., & <NAME>. (2013). Highly comparative time-series analysis: the empirical structure of time series and their methods. Journal of the Royal Society Interface, 10(83), 20130048.  1. Imports<jupyter_code>from sklearn import metrics

from sktime.classification.feature_based import Catch22Classifier
from sktime.datasets import load_basic_motions, load_italy_power_demand
from sktime.transformations.panel.catch22 import Catch22<jupyter_output><empty_output><jupyter_text>2. Load data<jupyter_code>IPD_X_train, IPD_y_train = load_italy_power_demand(split="train", return_X_y=True)
IPD_X_test, IPD_y_test = load_italy_power_demand(split="test", return_X_y=True)
IPD_X_test = IPD_X_test[:50]
IPD_y_test = IPD_y_test[:50]

print(IPD_X_train.shape, IPD_y_train.shape, IPD_X_test.shape, IPD_y_test.shape)

BM_X_train, BM_y_train = load_basic_motions(split="train", return_X_y=True)
BM_X_test, BM_y_test = load_basic_motions(split="test", return_X_y=True)

print(BM_X_train.shape, BM_y_train.shape, BM_X_test.shape, BM_y_test.shape)<jupyter_output><empty_output><jupyter_text>3. catch22 transform UnivariateThe catch22 features are provided in the form of a transformer, `Catch22`.From this the transformed data can be used for a variety of time series analysis tasks.<jupyter_code>c22_uv = Catch22()
c22_uv.fit(IPD_X_train, IPD_y_train)
transformed_data_uv = c22_uv.transform(IPD_X_train)
print(transformed_data_uv.head())<jupyter_output><empty_output><jupyter_text>The transform `Catch22` method will process all 22 features.For individual features, the transform_single_feature method can be used when provided with a numeric feature ID or the feature name.<jupyter_code>transformed_feature_uv = c22_uv.transform_single_feature(IPD_X_train, "CO_f1ecac")
print(transformed_feature_uv)<jupyter_output><empty_output><jupyter_text>MultivariateTransformation of multivariate data is supported by `Catch22`.The default procedure will concatenate each column prior to transformation.<jupyter_code>c22_mv = Catch22()
c22_mv.fit(BM_X_train, BM_y_train)
transformed_data_mv = c22_mv.transform(BM_X_train)
print(transformed_data_mv.head())<jupyter_output><empty_output><jupyter_text>4. catch22 Forest ClassifierFor classification tasks the default classifier to use with the catch22 features is random forest classifier.An implementation making use of the `RandomForestClassifier` from sklearn built on catch22 features is provided in the form on the `Catch22Classifier` for ease of use.<jupyter_code>c22f = Catch22Classifier(random_state=0)
c22f.fit(IPD_X_train, IPD_y_train)
c22f_preds = c22f.predict(IPD_X_test)
print("C22F Accuracy: " + str(metrics.accuracy_score(IPD_y_test, c22f_preds)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08324768756423433, 'fraction_numerical': 0.03468653648509764, 'mean_word_length': 7.537280701754386, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '576590', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1213, 'n_words': 354, 'path': 'examples/catch22.ipynb', 'repo_name': 'benHeid/sktime', 'size': '3954'}