.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_basics/plot_02_daily_routines.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_01_basics_plot_02_daily_routines.py: An everyday example: daily routines =================================== Three hundred days of three kinds of people — early birds, commuters and remote workers — each a sequence of activities from waking up to going to sleep. The raw sequences are summarized by a *sunburst* (rings = steps, angle = number of days), the frequent sequences by a *prefix tree*, and the most typical patterns by a glyph table. Patterns may skip activities (``max_gap=2`` allows one activity in between). .. GENERATED FROM PYTHON SOURCE LINES 14-16 Look at the data first ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-24 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_patterns, plot_prefix_tree, plot_sunburst db = sv.datasets.make_daily_routines(300, random_state=0) print(db.stats()) print(sv.format_pattern(db[0])) plot_sunburst(db, max_depth=4, title="how the days begin") .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_02_daily_routines_001.png :alt: how the days begin :srcset: /auto_examples/01_basics/images/sphx_glr_plot_02_daily_routines_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none n_sequences 300.000000 n_items 19.000000 n_elements 3853.000000 avg_length 12.843333 min_length 9.000000 max_length 16.000000 avg_itemset_size 1.000000 avg_distinct_items 10.953333 density 0.576491 dtype: float64 wake up → shower → commute → work → meeting → lunch → work → commute → gym → tv → sleep .. GENERATED FROM PYTHON SOURCE LINES 25-27 Frequent sequences with a small gap ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python ps = sv.mine(db, min_support=0.3, max_gap=2, max_length=6) print(ps) plot_prefix_tree(ps, max_depth=4, max_children=3, title="frequent sequences as a tree (three most frequent continuations per node)") .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_02_daily_routines_002.png :alt: frequent sequences as a tree (three most frequent continuations per node) :srcset: /auto_examples/01_basics/images/sphx_glr_plot_02_daily_routines_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none PatternSet(n_patterns=96, algorithm='cmspam', min_support=0.3, n_sequences=300) .. GENERATED FROM PYTHON SOURCE LINES 31-33 The ten best patterns of length at least three ---------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python plot_patterns(ps.filter(min_length=3), top=10) .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_02_daily_routines_003.png :alt: top 10 patterns by support, rel support, confidence :srcset: /auto_examples/01_basics/images/sphx_glr_plot_02_daily_routines_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 36-40 Parameter study: the gap ------------------------ Without a gap constraint, patterns may join activities hours apart and their number grows; with ``max_gap=1`` only directly consecutive activities count. .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python for gap in (1, 2, 3, None): n = len(sv.mine(db, 0.3, max_gap=gap, max_length=6)) print(f"max_gap={gap}: {n} patterns") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none max_gap=1: 25 patterns max_gap=2: 96 patterns max_gap=3: 346 patterns max_gap=None: 1425 patterns .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.478 seconds) .. _sphx_glr_download_auto_examples_01_basics_plot_02_daily_routines.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/01_basics/plot_02_daily_routines.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_daily_routines.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_daily_routines.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_daily_routines.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_