.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_trees/plot_02_entropy_tree.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_03_trees_plot_02_entropy_tree.py: Where does the process branch? The continuation-entropy tree ============================================================ A new view: the prefix tree of web-shop journeys colored by the *entropy of what comes next* at every node, :math:`H=-\sum_e P(e\mid\text{prefix})\log_2 P(e\mid\text{prefix})` (the end of the journey included). Green nodes have a predictable next step, vermilion nodes are decision points where visitors scatter. For process monitoring the vermilion nodes are where an early warning or a nudge pays off. .. GENERATED FROM PYTHON SOURCE LINES 11-19 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_prefix_tree db = sv.datasets.make_customer_journeys(1000, random_state=0) plot_prefix_tree(db, max_depth=4, min_count=25, color_by="entropy", title="continuation entropy of the web-shop journeys") .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_02_entropy_tree_001.png :alt: continuation entropy of the web-shop journeys :srcset: /auto_examples/03_trees/images/sphx_glr_plot_02_entropy_tree_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 20-22 The numbers behind the colors ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python ps = sv.mine(db, 0.05, max_gap=1, max_length=4) ct = sv.measures.continuation_table(ps) print(ct.sort_values("entropy", ascending=False).head(8)[["pattern", "entropy", "top_next"]]) .. rst-class:: sphx-glr-script-out .. code-block:: none pattern ... top_next 40 home → category → product ... cart (0.29), exit (0.25), reviews (0.21) 15 category → product ... cart (0.27), exit (0.25), reviews (0.23) 64 search → product → reviews → product ... cart (0.33), reviews (0.24), search (0.16) 7 product ... cart (0.28), exit (0.26), reviews (0.24) 28 reviews → product ... cart (0.34), reviews (0.26), exit (0.16) 48 product → reviews → product ... cart (0.34), reviews (0.26), exit (0.16) 42 home → search → product ... exit (0.27), cart (0.27), reviews (0.26) 30 search → product ... cart (0.28), reviews (0.28), exit (0.26) [8 rows x 3 columns] .. GENERATED FROM PYTHON SOURCE LINES 27-30 Parameter study: history length ------------------------------- Does a longer history make the next page more predictable? Mean entropy by prefix length: .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python ct["length"] = ps.lengths print(ct.groupby("length")["entropy"].mean().round(2)) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none length 1 1.08 2 1.00 3 1.05 4 0.94 Name: entropy, dtype: float64 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.553 seconds) .. _sphx_glr_download_auto_examples_03_trees_plot_02_entropy_tree.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/03_trees/plot_02_entropy_tree.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_entropy_tree.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_entropy_tree.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_entropy_tree.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_