.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/06_sequences/plot_07_mdl_summary.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_06_sequences_plot_07_mdl_summary.py: A summary in a few patterns: MDL ================================ Instead of hundreds of frequent sequences, the Minimum Description Length principle picks the few that compress the data best (Krimp, SQS: Tatti & Vreeken, 2012). Every sequence is covered greedily by the selected patterns; the cover plot shows which runs of each day each pattern explains. .. GENERATED FROM PYTHON SOURCE LINES 10-21 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_cover db = sv.datasets.make_daily_routines(300, random_state=0) summary = sv.mdl_summary(db, min_support=0.1, max_length=8, max_patterns=12) print(f"{len(summary.patterns)} patterns, description length {summary.compression:.0%} of the singleton code") print(summary.to_frame()) plot_cover(db, summary, max_sequences=40, max_length=15) .. image-sg:: /auto_examples/06_sequences/images/sphx_glr_plot_07_mdl_summary_001.png :alt: MDL cover by 8 patterns (description length 76% of singletons) :srcset: /auto_examples/06_sequences/images/sphx_glr_plot_07_mdl_summary_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 8 patterns, description length 76% of the singleton code pattern support usage size 0 lunch → work → commute → gym → dinner → tv → s... 49 18 7 1 lunch → work → commute 144 81 3 2 shower → commute → work → meeting → lunch → wo... 41 10 8 3 work → commute → gym → dinner → tv → sleep 53 28 6 4 wake up → coffee → work → meeting → work → lun... 36 36 8 5 wake up → coffee → shower → commute → work → m... 42 42 7 6 wake up → coffee → work → meeting → work → lun... 41 5 7 7 wake up → run → shower → coffee → breakfast → ... 41 41 7 .. GENERATED FROM PYTHON SOURCE LINES 22-24 Parameter study: how many patterns ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python for k in (2, 5, 10, 20): s = sv.mdl_summary(db, min_support=0.1, max_length=8, max_patterns=k) print(f"{k:2d} patterns allowed: compression {s.compression:.2f}") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none 2 patterns allowed: compression 0.93 5 patterns allowed: compression 0.90 10 patterns allowed: compression 0.77 20 patterns allowed: compression 0.73 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.459 seconds) .. _sphx_glr_download_auto_examples_06_sequences_plot_07_mdl_summary.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/spmviz/main?urlpath=lab/tree/notebooks/auto_examples/06_sequences/plot_07_mdl_summary.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_07_mdl_summary.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_07_mdl_summary.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_07_mdl_summary.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_