.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/06_sequences/plot_06_episodes.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_06_episodes.py: Episodes in one long alarm stream ================================= Without trace boundaries, an alarm log is one long stream. Frequent *episodes* (Mannila, Toivonen & Verkamo, 1997) are found in sliding windows: a serial episode is ordered, a parallel one is a set. WINEPI counts the share of windows containing the episode, MINEPI its minimal occurrences; the timeline shows the minimal occurrences of the top episodes. .. GENERATED FROM PYTHON SOURCE LINES 11-28 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_episode_timeline alarm = sv.datasets.load_alarm_log() # the busiest day of the plant as a single stream (times in minutes) log = sv.datasets.load_alarm_log(as_frame=True) dates = log["timestamp"].dt.date day = log[dates == dates.value_counts().index[0]] events = [alarm.label(e) for e in day["event"]] minutes = (day["timestamp"] - day["timestamp"].iloc[0]).dt.total_seconds().to_numpy() / 60 ep = sv.mine_episodes(events, times=minutes, window=10, min_frequency=0.02, max_length=3) multi = ep.filter(min_length=2) print(multi.to_frame().sort_values("frequency", ascending=False).head(8)[["pattern", "frequency", "minimal_occurrences"]]) plot_episode_timeline(ep, top=8) .. image-sg:: /auto_examples/06_sequences/images/sphx_glr_plot_06_episodes_001.png :alt: minimal occurrences of the top serial episodes (window 10) :srcset: /auto_examples/06_sequences/images/sphx_glr_plot_06_episodes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none pattern frequency minimal_occurrences 50 O1132 → O1136 0.081720 12 27 O1085 → O1084 0.070784 14 22 O1084 → O1133 0.069472 14 55 O1133 → O1084 0.068102 13 20 O1084 → O1085 0.052308 10 56 O1133 → O1085 0.046610 9 28 O1085 → O1132 0.044434 8 47 O1132 → O1084 0.040532 7 .. GENERATED FROM PYTHON SOURCE LINES 29-31 Parallel episodes ----------------- .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: Python par = sv.mine_episodes(events, times=minutes, window=10, min_frequency=0.02, kind="parallel", max_length=3) print(par.to_frame().sort_values("frequency", ascending=False).head(6)[["pattern", "frequency"]]) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none pattern frequency 16 O1084 0.217348 2 A232 0.212386 23 O1133 0.210901 17 O1085 0.187372 1 A196 0.149787 22 O1132 0.120709 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.473 seconds) .. _sphx_glr_download_auto_examples_06_sequences_plot_06_episodes.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_06_episodes.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_06_episodes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_06_episodes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_06_episodes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_