binder

Deep learning based time series classification in aeon

There are a range of deep learning based classification algorithms in the toolkit. The networks that are common to classification, regression and clustering are in the networks module. Our deep learning classifiers are based those used in deep learning bake off [1] and recent experimentation [2]. [3] provides an extensive recent review of related deep learning work.

The use case for deep learning classifiers is identical to that of all classifiers. However, you need to have tensorflow installed in your environment. If you have a GPU correctly installed the classifiers should use them, although it is worth checking the output.

[1]:
from sklearn.metrics import accuracy_score

from aeon.classification.deep_learning import TimeCNNClassifier
from aeon.datasets import load_basic_motions  # multivariate dataset
from aeon.datasets import load_italy_power_demand  # univariate dataset

italy, italy_labels = load_italy_power_demand(split="train")
italy_test, italy_test_labels = load_italy_power_demand(split="test")
motions, motions_labels = load_basic_motions(split="train")
motions_test, motions_test_labels = load_basic_motions(split="train")
cnn = TimeCNNClassifier(n_epochs=10)
cnn.fit(italy, italy_labels)
y_pred = cnn.predict(italy_test)
accuracy_score(italy_test_labels, y_pred)
2024-11-12 08:25:34.582860: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-11-12 08:25:34.583988: I external/local_tsl/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.
2024-11-12 08:25:34.626288: I external/local_tsl/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.
2024-11-12 08:25:34.772595: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-11-12 08:25:35.886826: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
65/65 ━━━━━━━━━━━━━━━━━━━━ 0s 2ms/step
[1]:
0.49854227405247814

Classifier Details

The deep learning bake off [1] found that the Residual Network (ResNet) was the best performing architecture for TSC. ResNet has the following network structure.

ROCKET.

The Inception Time deep learning algorithm was proposed subsequent to [1]. InceptionTimeClassifier is an ensemble of five IndividualInceptionClassifier deep learning classifiers. Each base classifier shares the same architecture based on Inception modules. Diversity is achieved through randomly initialising weights. A IndividualInceptionClassifier has the following structure.

ROCKET.

An IndividualInceptionClassifier is structured as follows.

ROCKET.

Performance on the UCR univariate datasets

You can find the dictionary based classifiers as follows. Please note we have not fully evaluated all the deep learners yet, they take a long time to run.

[2]:
from aeon.utils.discovery import all_estimators

est = all_estimators("classifier", tag_filter={"algorithm_type": "deeplearning"})
for c in est:
    print(c)
/home/afawaz/phd/venvs/aeon-dev-py39/lib/python3.9/site-packages/numba/np/ufunc/parallel.py:371: NumbaWarning: The TBB threading layer requires TBB version 2021 update 6 or later i.e., TBB_INTERFACE_VERSION >= 12060. Found TBB_INTERFACE_VERSION = 12050. The TBB threading layer is disabled.
  warnings.warn(problem)
('DisjointCNNClassifier', <class 'aeon.classification.deep_learning._disjoint_cnn.DisjointCNNClassifier'>)
('EncoderClassifier', <class 'aeon.classification.deep_learning._encoder.EncoderClassifier'>)
('FCNClassifier', <class 'aeon.classification.deep_learning._fcn.FCNClassifier'>)
('InceptionTimeClassifier', <class 'aeon.classification.deep_learning._inception_time.InceptionTimeClassifier'>)
('IndividualInceptionClassifier', <class 'aeon.classification.deep_learning._inception_time.IndividualInceptionClassifier'>)
('IndividualLITEClassifier', <class 'aeon.classification.deep_learning._lite_time.IndividualLITEClassifier'>)
('LITETimeClassifier', <class 'aeon.classification.deep_learning._lite_time.LITETimeClassifier'>)
('MLPClassifier', <class 'aeon.classification.deep_learning._mlp.MLPClassifier'>)
('ResNetClassifier', <class 'aeon.classification.deep_learning._resnet.ResNetClassifier'>)
('TimeCNNClassifier', <class 'aeon.classification.deep_learning._cnn.TimeCNNClassifier'>)
[8]:
from aeon.benchmarking.results_loaders import get_estimator_results_as_array
from aeon.datasets.tsc_datasets import univariate

names = [t[0].replace("Classifier", "") for t in est]
# Not done these yet
names.remove("Encoder")
names.remove("FCN")
names.remove("IndividualInception")
names.remove("IndividualLITE")
names.remove("MLP")
names.remove("TimeCNN")
names.remove("DisjointCNN")  # Multivariate only
names.append("CNN")  # using old name


results, present_names = get_estimator_results_as_array(
    names, univariate, include_missing=False
)
results.shape
[8]:
(112, 4)
[9]:
from aeon.visualisation import plot_boxplot, plot_critical_difference

plot_critical_difference(results, names)
[9]:
(<Figure size 600x230 with 1 Axes>, <Axes: >)
../../_images/examples_classification_deep_learning_8_1.png
[11]:
plot_boxplot(results, names, relative=True)
[11]:
(<Figure size 1000x600 with 1 Axes>, <Axes: >)
../../_images/examples_classification_deep_learning_9_1.png

References

[1] Fawaz et al. (2019) “Deep learning for time series classification: a review” Data Mining and Knowledge Discovery. 33(4): 917-963

[2] Fawaz et al. (2020) “InceptionTime: finding AlexNet for time series classification. Data Mining and Knowledge Discovery. 34(6): 1936-1962

[3] Foumani et al. (2023) “Deep Learning for Time Series Classification and Extrinsic Regression: A Current Survey” ArXiv https://arxiv.org/pdf/2302.02515.pdf

[4] https://github.com/MSD-IRIMAS/CF-4-TSC


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