.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_warping/plot_04_diagnostics_learning.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_04_diagnostics_learning.py: Diagnosing and tuning warping ============================= How much warping does a data set need? Path statistics (the share of diagonal steps, the longest horizontal or vertical run, the area between the path and the diagonal) and the tightness of warping (ToW) describe the alignments; the window that maximizes the leave-one-out accuracy can be learned (Ratanamahatana and Keogh, 2004); and an elastic ensemble (Lines and Bagnall, 2015) combines several measures. .. GENERATED FROM PYTHON SOURCE LINES 12-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mvtsa import viz from mvtsa import warping as wp from mvtsa.datasets import make_cbf C, y = make_cbf(n_per_class=12, length=96, random_state=2) .. GENERATED FROM PYTHON SOURCE LINES 23-25 Path statistics of a pair ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: Python res = wp.dtw_path(C[0], C[1]) print({k: round(v, 3) for k, v in wp.path_statistics(res.path).items()}) paths = [wp.dtw_path(C[0], C[j]).path for j in (1, 2, 3)] viz.plot_warping_function(paths, labels=["pair 0-1", "pair 0-2", "pair 0-3"]) .. image-sg:: /auto_examples/05_warping/images/sphx_glr_plot_04_diagnostics_learning_001.png :alt: plot 04 diagnostics learning :srcset: /auto_examples/05_warping/images/sphx_glr_plot_04_diagnostics_learning_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none {'length': 124.0, 'tightness': 1.292, 'warping_amount': 0.455, 'max_horizontal': 6.0, 'max_vertical': 6.0, 'area': 0.028, 'pathology': 0.062} .. GENERATED FROM PYTHON SOURCE LINES 31-33 Learning the warping window --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: Python best, scores = wp.learn_window( C, y, candidates=(0.0, 0.02, 0.05, 0.1, 0.2, None) ) print( "accuracy by window:", {str(k): round(v, 3) for k, v in scores.items()}, "-> best", best, ) .. rst-class:: sphx-glr-script-out .. code-block:: none accuracy by window: {'0.0': 0.889, '0.02': 0.917, '0.05': 0.944, '0.1': 0.972, '0.2': 0.944, 'None': 0.944} -> best 0.1 .. GENERATED FROM PYTHON SOURCE LINES 43-45 An elastic ensemble ------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-59 .. code-block:: Python rng = np.random.default_rng(0) idx = rng.permutation(len(C)) train, test = idx[:24], idx[24:] ee = wp.ElasticEnsemble( metrics=("dtw", "ddtw", "msm", ("lcss", {"epsilon": 0.5})) ).fit([C[i] for i in train], y[train]) pred = ee.predict([C[i] for i in test]) print( "weights:", {k: round(v, 2) for k, v in ee.weights_.items()}, "| test accuracy:", np.mean(pred == y[test]), ) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none weights: {'dtw': 0.88, 'ddtw': 0.71, 'msm': 1.0, 'lcss': 1.0} | test accuracy: 1.0 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.378 seconds) .. _sphx_glr_download_auto_examples_05_warping_plot_04_diagnostics_learning.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_04_diagnostics_learning.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_diagnostics_learning.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_diagnostics_learning.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_diagnostics_learning.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_