.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_warping/plot_02_dtw_variants.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_05_warping_plot_02_dtw_variants.py: A family of elastic measures on Cylinder--Bell--Funnel ====================================================== The CBF problem (Saito, 1994) is the classic test of elastic measures: the three classes differ in shape, but the onset and length of the events vary. The leave-one-out 1-nearest-neighbour accuracy compares Euclidean distance, DTW and its variants (derivative, weighted, amerced, shape-based) and the edit-type measures (LCSS, EDR, ERP, TWED, MSM). .. GENERATED FROM PYTHON SOURCE LINES 11-24 .. code-block:: Python import time import matplotlib.pyplot as plt import pandas as pd from mvtsa import pairwise_distances, viz from mvtsa.datasets import make_cbf from mvtsa.evaluation import knn_accuracy C, y = make_cbf(n_per_class=15, length=96, random_state=0) viz.plot_cluster_prototypes(C, y, ncols=3) .. image-sg:: /auto_examples/05_warping/images/sphx_glr_plot_02_dtw_variants_001.png :alt: cluster 0 (n=15), cluster 1 (n=15), cluster 2 (n=15) :srcset: /auto_examples/05_warping/images/sphx_glr_plot_02_dtw_variants_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 25-27 Leave-one-out 1-NN accuracy --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-63 .. code-block:: Python measures = { "euclidean": {}, "dtw": {}, "dtw (10% band)": {"metric": "dtw", "window": 0.1}, "ddtw": {}, "wdtw": {"g": 0.05}, "adtw": {"penalty": 0.5}, "shape_dtw": {"width": 9}, "lcss": {"epsilon": 0.5, "delta": 10}, "edr": {"epsilon": 0.25}, "erp": {}, "twed": {}, "msm": {"c": 0.5}, "sbd": {}, } rows = [] for name, kw in measures.items(): kw = dict(kw) metric = kw.pop("metric", name) t0 = time.perf_counter() D = pairwise_distances(C, metric=metric, **kw) rows.append( { "measure": name, "1-NN accuracy": knn_accuracy(D, y), "seconds": time.perf_counter() - t0, } ) table = pd.DataFrame(rows).sort_values("1-NN accuracy", ascending=False) print(table.round(3).to_string(index=False)) fig, ax = plt.subplots(figsize=(6, 3.2)) ax.barh(table["measure"], table["1-NN accuracy"], color="#285780") ax.invert_yaxis() ax.set_xlabel("leave-one-out 1-NN accuracy") ax.set_xlim(0.5, 1.0) plt.show() .. image-sg:: /auto_examples/05_warping/images/sphx_glr_plot_02_dtw_variants_002.png :alt: plot 02 dtw variants :srcset: /auto_examples/05_warping/images/sphx_glr_plot_02_dtw_variants_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none measure 1-NN accuracy seconds wdtw 1.000 0.105 edr 1.000 0.196 lcss 1.000 0.245 shape_dtw 1.000 0.283 adtw 1.000 0.068 erp 1.000 0.253 twed 1.000 2.849 msm 1.000 0.258 dtw (10% band) 0.978 0.060 dtw 0.978 0.068 sbd 0.933 0.028 euclidean 0.911 0.006 ddtw 0.711 0.080 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.666 seconds) .. _sphx_glr_download_auto_examples_05_warping_plot_02_dtw_variants.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/mvtsa/main?urlpath=lab/tree/notebooks/auto_examples/05_warping/plot_02_dtw_variants.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_dtw_variants.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_dtw_variants.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_dtw_variants.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_