{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "dcbe2174-a691-4093-ab80-d796edb5121d", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 19, "id": "d1779970-eefb-4577-9c4e-e0a19ceadcc1", "metadata": {}, "outputs": [ { "data": { "text/plain": "((40, 6, 100), (40, 6, 100))" }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import warnings\n", "\n", "warnings.filterwarnings(\"ignore\")\n", "from sklearn.linear_model import RidgeClassifierCV\n", "from sklearn.pipeline import make_pipeline\n", "\n", "from aeon.datasets import load_basic_motions\n", "from aeon.transformations.collection import channel_selection\n", "from aeon.transformations.collection.convolution_based import Rocket\n", "\n", "X_train, y_train = load_basic_motions(split=\"train\")\n", "X_test, y_test = load_basic_motions(split=\"test\")\n", "X_train.shape, X_test.shape" ] }, { "cell_type": "markdown", "id": "0437ca7a-5b5a-4e28-b565-0b2df4eac60d", "metadata": {}, "source": [ "## 1 Channel Selection in a Pipeline\n", "\n", "``ElbowClassPairwise`` and ``ElbowClassSum`` are aeon transformers, so can be used in\n", " a pipeline with other transformers and suitable classifiers." ] }, { "cell_type": "code", "execution_count": 15, "id": "830137a3-10c3-49b9-9a98-7062dc7ab1d8", "metadata": {}, "outputs": [], "source": [ "# cs = channel_selection.ElbowClassSum() # ECS\n", "cs = channel_selection.ElbowClassPairwise(prototype_type=\"mad\") # ECP\n", "rocket_pipeline = make_pipeline(cs, Rocket(), RidgeClassifierCV())" ] }, { "cell_type": "code", "execution_count": 16, "outputs": [ { "data": { "text/plain": "1.0" }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rocket_pipeline.fit(X_train, y_train)\n", "rocket_pipeline.score(X_test, y_test)" ], "metadata": { "collapsed": false }, "id": "53e0fefe6aaf3110" }, { "cell_type": "markdown", "id": "d18ac8bc-a83a-4dd7-b577-aefc25d7bed6", "metadata": {}, "source": [ "## 4 Identify channels selected\n", "We can recover the selected channels from the transformer, and recover the centroids\n", "uses in the selection process. We can of course do this directly from the transform" ] }, { "cell_type": "code", "execution_count": 17, "id": "35a44d68-7bce-44b0-baf3-e4f11606001c", "metadata": {}, "outputs": [ { "data": { "text/plain": "[0, 1]" }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X_selected = cs.fit(X_train, y_train)\n", "cs.channels_selected_idx" ] }, { "cell_type": "code", "execution_count": 18, "outputs": [ { "data": { "text/plain": " Centroid_badminton_running Centroid_badminton_standing \\\n0 72.883920 37.486167 \n1 82.974076 19.586588 \n2 21.381712 18.196532 \n3 11.289843 9.402970 \n4 8.140510 6.623146 \n5 29.041896 9.025905 \n\n Centroid_badminton_walking Centroid_running_standing \\\n0 32.843063 95.139594 \n1 28.068407 87.661718 \n2 17.131596 26.885354 \n3 9.932407 7.750558 \n4 6.877631 6.112858 \n5 12.876751 27.785727 \n\n Centroid_running_walking Centroid_standing_walking \n0 89.360656 9.786164 \n1 89.326726 21.778564 \n2 24.524588 4.834320 \n3 8.613671 3.744539 \n4 6.304372 1.546983 \n5 28.527294 9.650223 ", "text/html": "
| \n | Centroid_badminton_running | \nCentroid_badminton_standing | \nCentroid_badminton_walking | \nCentroid_running_standing | \nCentroid_running_walking | \nCentroid_standing_walking | \n
|---|---|---|---|---|---|---|
| 0 | \n72.883920 | \n37.486167 | \n32.843063 | \n95.139594 | \n89.360656 | \n9.786164 | \n
| 1 | \n82.974076 | \n19.586588 | \n28.068407 | \n87.661718 | \n89.326726 | \n21.778564 | \n
| 2 | \n21.381712 | \n18.196532 | \n17.131596 | \n26.885354 | \n24.524588 | \n4.834320 | \n
| 3 | \n11.289843 | \n9.402970 | \n9.932407 | \n7.750558 | \n8.613671 | \n3.744539 | \n
| 4 | \n8.140510 | \n6.623146 | \n6.877631 | \n6.112858 | \n6.304372 | \n1.546983 | \n
| 5 | \n29.041896 | \n9.025905 | \n12.876751 | \n27.785727 | \n28.527294 | \n9.650223 | \n