.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_modern_segmentation/plot_05_consensus.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_04_modern_segmentation_plot_05_consensus.py: Consensus of segmentations ========================== Different segmenters make different mistakes. The boundary agreement -- the kernel-smoothed fraction of members that place a change point near every sample -- shows where they agree, and its peaks above one half form a consensus segmentation. .. GENERATED FROM PYTHON SOURCE LINES 10-26 .. code-block:: Python import matplotlib.pyplot as plt import mvtsa as mv from mvtsa import segmentation as sg from mvtsa.evaluation import evaluate_segmentation X, cps, _ = mv.datasets.make_piecewise_stationary( n_segments=5, length=150, n_variables=3, change="all", vary=0.3, random_state=21, ) .. GENERATED FROM PYTHON SOURCE LINES 27-29 Members and consensus --------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-53 .. code-block:: Python members = [ sg.BottomUp("normal", n_segments=5, initial_size=10), sg.PELT("normal", penalty=200, jump=5, min_size=20), sg.TopDown("kernel", n_segments=5, jump=5), sg.BOCPD(hazard=150), sg.WindowDiscrepancy("normal", width=40, n_segments=5), ] cons = sg.ConsensusSegmenter(members, threshold=0.5) seg = cons.segment(X) for m, s in zip( ["bottom-up", "PELT", "top-down", "BOCPD", "window"], cons.members_, strict=True, ): print(f"{m:9s} {s.change_points}") print("consensus", seg.change_points, "| true", cps) print(evaluate_segmentation(cps, seg, len(X), margin=10)["f1"]) mv.viz.plot_boundary_agreement( cons.agreement_, members=cons.members_, consensus=seg, names=["bottom-up", "PELT", "top-down", "BOCPD", "window"], ) plt.show() .. image-sg:: /auto_examples/04_modern_segmentation/images/sphx_glr_plot_05_consensus_001.png :alt: plot 05 consensus :srcset: /auto_examples/04_modern_segmentation/images/sphx_glr_plot_05_consensus_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none bottom-up [160 330 480 600] PELT [165 325 485 595] top-down [167 324 484 596] BOCPD [169 323 486 595] window [169 323 486 595] consensus [166 325 484 596] | true [169 323 486 595] 1.0 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.310 seconds) .. _sphx_glr_download_auto_examples_04_modern_segmentation_plot_05_consensus.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/04_modern_segmentation/plot_05_consensus.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_consensus.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_consensus.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_consensus.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_