.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/08_evaluation/plot_01_metrics.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_08_evaluation_plot_01_metrics.py: Measuring segmentation quality ============================== No single number describes how good a segmentation is. The F1 score of the change points within a margin counts detections; the covering (Arbelaez et al., 2011) measures how well the segments overlap; the Hausdorff distance gives the worst boundary error; the annotation error compares the numbers of change points. The example shows how the metrics react to typical mistakes. .. GENERATED FROM PYTHON SOURCE LINES 12-30 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import pandas as pd from mvtsa.evaluation import evaluate_segmentation T = 1000 truth = np.array([200, 400, 600, 800]) cases = { "perfect": truth, "shifted by 15": truth + 15, "one missed": truth[[0, 1, 3]], "one extra": np.sort(np.r_[truth, 500]), "many extra": np.arange(50, 1000, 50), "nothing": np.array([], int), } .. GENERATED FROM PYTHON SOURCE LINES 31-33 Metrics for typical mistakes ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 33-49 .. code-block:: Python rows = [ {"case": k, **evaluate_segmentation(truth, v, T, margin=10)} for k, v in cases.items() ] table = pd.DataFrame(rows)[ [ "case", "precision", "recall", "f1", "covering", "hausdorff", "annotation_error", ] ] print(table.round(3).to_string(index=False)) .. rst-class:: sphx-glr-script-out .. code-block:: none case precision recall f1 covering hausdorff annotation_error perfect 1.000 1.00 1.000 1.000 0.0 0 shifted by 15 0.000 0.00 0.000 0.887 15.0 0 one missed 1.000 0.75 0.857 0.800 200.0 1 one extra 0.800 1.00 0.889 0.900 100.0 1 many extra 0.211 1.00 0.348 0.250 150.0 15 nothing 0.000 0.00 0.000 0.200 inf 4 .. GENERATED FROM PYTHON SOURCE LINES 50-52 Parameter study: the margin of the F1 score ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 52-67 .. code-block:: Python fig, ax = plt.subplots(figsize=(5, 3)) margins = np.arange(0, 41, 2) ax.plot( margins, [ evaluate_segmentation(truth, truth + 15, T, margin=m)["f1"] for m in margins ], "o-", color="#285780", ms=3, ) ax.set_xlabel("margin (samples)") ax.set_ylabel("F1, change points shifted by 15") plt.show() .. image-sg:: /auto_examples/08_evaluation/images/sphx_glr_plot_01_metrics_001.png :alt: plot 01 metrics :srcset: /auto_examples/08_evaluation/images/sphx_glr_plot_01_metrics_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.110 seconds) .. _sphx_glr_download_auto_examples_08_evaluation_plot_01_metrics.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/08_evaluation/plot_01_metrics.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_metrics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_metrics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_metrics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_