[1]:
import warnings
warnings.filterwarnings("ignore")
Channel Selection in Multivariate Time Series Classification#
Overview#
Sometimes every channel is not required to perform classification; only a few are useful. The [1] proposed a fast channel selection technique for Multivariate Time Classification.
[1] : Fast Channel Selection for Scalable Multivariate Time Series Classification Link
[2]:
from sklearn.linear_model import RidgeClassifierCV
from sklearn.pipeline import make_pipeline
from sktime.datasets import load_UCR_UEA_dataset
from sktime.transformations.panel import channel_selection
from sktime.transformations.panel.rocket import Rocket
1 Initialise the Pipeline#
[3]:
# cs = channel_selection.ElbowClassSum() # ECS
cs = channel_selection.ElbowClassPairwise() # ECP
[4]:
rocket_pipeline = make_pipeline(cs, Rocket(), RidgeClassifierCV())
2 Load and Fit the Training Data#
[5]:
data = "BasicMotions"
X_train, y_train = load_UCR_UEA_dataset(data, split="train", return_X_y=True)
X_test, y_test = load_UCR_UEA_dataset(data, split="test", return_X_y=True)
[6]:
rocket_pipeline.fit(X_train, y_train)
[6]:
Pipeline(steps=[('elbowclasspairwise', ElbowClassPairwise()),
('rocket', Rocket()),
('ridgeclassifiercv',
RidgeClassifierCV(alphas=array([ 0.1, 1. , 10. ])))])
3 Classify the Test Data#
[7]:
rocket_pipeline.score(X_test, y_test)
[7]:
1.0
4 Identify channels#
[8]:
rocket_pipeline.steps[0][1].channels_selected_
[8]:
[0, 1]
[9]:
rocket_pipeline.steps[0][1].distance_frame_
[9]:
Centroid_badminton_running | Centroid_badminton_standing | Centroid_badminton_walking | Centroid_running_standing | Centroid_running_walking | Centroid_standing_walking | |
---|---|---|---|---|---|---|
0 | 39.594679 | 55.752785 | 48.440779 | 63.610220 | 57.247383 | 10.717044 |
1 | 57.681767 | 24.390543 | 27.770269 | 60.458125 | 62.339120 | 16.370347 |
2 | 20.175911 | 24.126969 | 22.331621 | 25.671979 | 22.991555 | 4.897452 |
3 | 12.546212 | 12.439152 | 12.741854 | 6.317654 | 6.695743 | 3.585273 |
4 | 10.101196 | 8.865871 | 9.221908 | 6.520172 | 6.715702 | 1.299989 |
5 | 23.464251 | 14.568685 | 13.953445 | 18.878429 | 19.768549 | 7.228389 |
5 Standalone#
[10]:
cs.fit(X_train, y_train)
[10]:
ElbowClassPairwise()
6 Distance Matrix#
[11]:
cs.distance_frame_
[11]:
Centroid_badminton_running | Centroid_badminton_standing | Centroid_badminton_walking | Centroid_running_standing | Centroid_running_walking | Centroid_standing_walking | |
---|---|---|---|---|---|---|
0 | 39.594679 | 55.752785 | 48.440779 | 63.610220 | 57.247383 | 10.717044 |
1 | 57.681767 | 24.390543 | 27.770269 | 60.458125 | 62.339120 | 16.370347 |
2 | 20.175911 | 24.126969 | 22.331621 | 25.671979 | 22.991555 | 4.897452 |
3 | 12.546212 | 12.439152 | 12.741854 | 6.317654 | 6.695743 | 3.585273 |
4 | 10.101196 | 8.865871 | 9.221908 | 6.520172 | 6.715702 | 1.299989 |
5 | 23.464251 | 14.568685 | 13.953445 | 18.878429 | 19.768549 | 7.228389 |
[12]:
cs.train_time_
[12]:
13
Generated using nbsphinx. The Jupyter notebook can be found here.