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 sktime.classification.deep_learning.lstmfcn import LSTMFCNClassifier
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 LSTM-FCN#

In this exampe we use a LSTM-FCN (LongShort Term Memory Fully Convolutional Network) classifier originally implemented in sktime-dl. Other classifiers provided by sktime-dl include CNN, MLP, ResNet, InceptionTime and MCDCNN.

The LSTM-FCN estimator is compatible with scikit-learn and can use sklearn’s GridSearchCV.

[ ]:
network = LSTMFCNClassifier(n_epochs=65, verbose=0)
network.fit(X_train, y_train)
network.score(X_test, y_test)

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