.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_nbvfs/plot_01_weighted_network.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_02_nbvfs_plot_01_weighted_network.py: NBVFS-WN: the weighted extension network ========================================= Bántay & Abonyi (2024) draw frequent sequences as a network: every sequence is a node, and an edge joins it to each of its one-event extensions. The edge weight is the *confidence* of the extension, :math:`c(\varphi_j)=\sigma(\varphi_j)/\sigma(\varphi_i)`: the share of the sequences containing :math:`\varphi_i` that continue with the added event. Node color is the length, node size the cumulative confidence (the share of the start event's sequences that reach the node). With a maximum gap the frequent sequences are prefix-closed, so the network is a forest rooted at the frequent single events. The data are the UWV clickstream of the paper (343 sessions, 14 services); as in the paper, CM-SPAM mines it with 1% minimum support, maximum gap 1 and maximum length 10. .. GENERATED FROM PYTHON SOURCE LINES 18-23 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv .. GENERATED FROM PYTHON SOURCE LINES 24-26 Mining as in the paper ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: Python db = sv.datasets.load_clickstream() ps = sv.mine(db, min_support=0.01, algorithm="cmspam", max_gap=1, max_length=10) print(ps, "lengths", ps.lengths.min(), "-", ps.lengths.max()) print({k: db.label(k) for k in range(4)}) .. rst-class:: sphx-glr-script-out .. code-block:: none PatternSet(n_patterns=241, algorithm='cmspam', min_support=0.01, n_sequences=343) lengths 1 - 8 {0: 'Your last employer', 1: 'The dismissal', 2: 'Hours worked', 3: 'Other work/income'} .. GENERATED FROM PYTHON SOURCE LINES 31-34 Circle layout: one starting event in the center ----------------------------------------------- The paper filters the network by the starting event; event 2 is "Hours worked". .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python wn = sv.NBVFS("wn", layout="circle", start_items=[2]).fit(ps) wn.plot(labels=20, title="NBVFS-WN, sequences starting with 'Hours worked'") .. image-sg:: /auto_examples/02_nbvfs/images/sphx_glr_plot_01_weighted_network_001.png :alt: NBVFS-WN, sequences starting with 'Hours worked' :srcset: /auto_examples/02_nbvfs/images/sphx_glr_plot_01_weighted_network_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 37-39 Hierarchical layout of all trees -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python sv.NBVFS("wn", layout="hierarchical", start_items=[0, 1, 2, 3]).fit(ps).plot(labels=12) .. image-sg:: /auto_examples/02_nbvfs/images/sphx_glr_plot_01_weighted_network_002.png :alt: NBVFS-WN weighted network :srcset: /auto_examples/02_nbvfs/images/sphx_glr_plot_01_weighted_network_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 42-46 Parameter study: pruning weak extensions ---------------------------------------- Edges below a confidence threshold (and the subtrees below them) disappear; the strong continuations of a process stand out. .. GENERATED FROM PYTHON SOURCE LINES 46-51 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(14, 4.8)) for ax, mc in zip(axes, (0.0, 0.2, 0.4)): m = sv.NBVFS("wn", start_items=[2], min_confidence=mc).fit(ps) m.plot(ax=ax, legend=False, labels=10, title=f"min confidence {mc}: {m.graph_.number_of_nodes()} nodes") plt.show() .. image-sg:: /auto_examples/02_nbvfs/images/sphx_glr_plot_01_weighted_network_003.png :alt: min confidence 0.0: 42 nodes, min confidence 0.2: 35 nodes, min confidence 0.4: 14 nodes :srcset: /auto_examples/02_nbvfs/images/sphx_glr_plot_01_weighted_network_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.328 seconds) .. _sphx_glr_download_auto_examples_02_nbvfs_plot_01_weighted_network.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/02_nbvfs/plot_01_weighted_network.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_weighted_network.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_weighted_network.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_weighted_network.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_