.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_flows/plot_02_transition_graph.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_flows_plot_02_transition_graph.py: Transition graphs, matrices and MatrixWave ========================================== The directly-follows graph of process mining (van der Aalst, 2016) counts consecutive pairs: a first-order summary that is easy to read but forgets the history. The same information as a row-normalized transition matrix, and as a MatrixWave-style sequence of step-by-step matrices (Zhao et al., 2015). .. GENERATED FROM PYTHON SOURCE LINES 10-20 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_matrixwave, plot_transition_graph, plot_transition_matrix db = sv.datasets.make_customer_journeys(1000, random_state=0) plot_transition_graph(db, top_edges=24) G = sv.networks.transition_graph(db) # networkx.DiGraph with counts and probabilities print(G["product"]["cart"]) .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_001.png :alt: transition (directly-follows) graph :srcset: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none {'count': 273, 'probability': 0.2932330827067669, 'n_sequences': 254, 'weight': 273.0} .. GENERATED FROM PYTHON SOURCE LINES 21-23 Transition matrix ----------------- .. GENERATED FROM PYTHON SOURCE LINES 23-25 .. code-block:: Python plot_transition_matrix(db) .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_002.png :alt: transition matrix :srcset: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 26-28 MatrixWave: one matrix per step ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python plot_matrixwave(db, steps=3, top=6) .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_003.png :alt: transition matrices between consecutive steps, step 1 → 2, step 2 → 3, step 3 → 4 :srcset: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 31-33 Parameter study: the frequency filter ------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 33-37 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(14, 5)) for ax, k in zip(axes, (10, 40)): plot_transition_graph(db, ax=ax, top_edges=k, labels=None, title=f"{k} strongest transitions") plt.show() .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_004.png :alt: 10 strongest transitions, 40 strongest transitions :srcset: /auto_examples/04_flows/images/sphx_glr_plot_02_transition_graph_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.490 seconds) .. _sphx_glr_download_auto_examples_04_flows_plot_02_transition_graph.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/04_flows/plot_02_transition_graph.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_transition_graph.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_transition_graph.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_transition_graph.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_