.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_latent_segmentation/plot_04_fuzzy_segmentation.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_03_latent_segmentation_plot_04_fuzzy_segmentation.py: Fuzzy segmentation with the modified Gath--Geva algorithm ========================================================= Abonyi, Feil, Nemeth and Arva (2005) treat segmentation as clustering in which every cluster has a Gaussian membership in *time* and a probabilistic PCA model of the variables. The memberships are fuzzy, so gradual transitions show up as overlapping segments; compatible clusters are merged and a monotone crisp labelling is read off at the end. .. GENERATED FROM PYTHON SOURCE LINES 11-22 .. 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_correlation_switching( n_segments=4, length=150, random_state=0 ) .. GENERATED FROM PYTHON SOURCE LINES 23-25 Memberships and crisp segments ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 25-40 .. code-block:: Python gg = sg.GGSegmenter( n_segments=6, n_components=1 ) # start with more clusters than needed seg = gg.segment(X) print( "clusters after merging:", seg.n_segments, "| change points:", seg.change_points, "| true:", cps, ) print(evaluate_segmentation(cps, seg, len(X), margin=10)["f1"]) mv.viz.plot_fuzzy_segmentation(X, seg) .. image-sg:: /auto_examples/03_latent_segmentation/images/sphx_glr_plot_04_fuzzy_segmentation_001.png :alt: plot 04 fuzzy segmentation :srcset: /auto_examples/03_latent_segmentation/images/sphx_glr_plot_04_fuzzy_segmentation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none clusters after merging: 4 | change points: [150 299 450] | true: [150 300 450] 1.0
.. GENERATED FROM PYTHON SOURCE LINES 41-45 Parameter study: the initial number of clusters ----------------------------------------------- The merging step removes the surplus clusters as long as the start is generous. .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python for c in (4, 6, 8, 10): s = sg.GGSegmenter(n_segments=c, n_components=1).segment(X) print( f"start {c:2d} -> {s.n_segments} segments, F1 {evaluate_segmentation(cps, s, len(X), 10)['f1']:.2f}" ) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none start 4 -> 4 segments, F1 1.00 start 6 -> 4 segments, F1 1.00 start 8 -> 4 segments, F1 1.00 start 10 -> 4 segments, F1 1.00 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.575 seconds) .. _sphx_glr_download_auto_examples_03_latent_segmentation_plot_04_fuzzy_segmentation.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/03_latent_segmentation/plot_04_fuzzy_segmentation.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_fuzzy_segmentation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_fuzzy_segmentation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_fuzzy_segmentation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_