binder

Multi-variate time series classification using a simple CNN#

In this notebook, we use sktime to perform for multi-variate time series classification by deep learning.

[ ]:
import numpy as np
import seaborn as sns
from sklearn.model_selection import GridSearchCV

from sktime.classification.deep_learning.cnn import CNNClassifier
from sktime.datasets import load_basic_motions

sns.set_style("whitegrid")

Load a dataset#

The Basic Motions dataset, from timeseriesclassification.com, has time series in six dimensions.

[ ]:
X_train, y_train = load_basic_motions(split="train", return_X_y=True)
X_test, y_test = load_basic_motions(split="test", return_X_y=True)
print(X_train.shape)
print(X_test.shape)
print(type(X_train.iloc[1, 1]))
X_train.head()
[ ]:
# The class labels
np.unique(y_train)

Train a deep neural network classifier#

Here we choose to use the CNN (convolutional neural network) classifier. Other classifiers provided by sktime-dl include MLP, ResNet, InceptionTime and MCDCNN (Multi Channel Deep Convolutional Neural Network)

[ ]:
network = CNNClassifier(n_epochs=200, verbose=True)
network.fit(X_train, y_train)
network.score(X_test, y_test)

Generated using nbsphinx. The Jupyter notebook can be found here.