.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_trees/plot_04_contrast_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_04_contrast_tree.py: Comparing two groups: contrast sunburst ======================================= Mobile and desktop visitors walk through the same shop differently. The contrast sunburst colors every prefix by the log-ratio of its relative frequency in the two groups (blue: more frequent on desktop, vermilion: on mobile). The contrast table of the frequent sequences adds Fisher's exact test (Dong & Li, 1999, emerging patterns). .. GENERATED FROM PYTHON SOURCE LINES 11-23 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_sunburst db = sv.datasets.make_customer_journeys(1500, random_state=2) plot_sunburst(db, max_depth=4, color_by="contrast", groups="device", positive="desktop", title="desktop (blue) versus mobile (vermilion)") ps = sv.mine(db, 0.03, max_gap=1, max_length=5) table = sv.measures.contrast(ps, "device", positive="desktop") print(table.head(8)[["pattern", "supp[desktop]", "supp[mobile]", "log2_ratio", "p_value"]]) .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_04_contrast_tree_001.png :alt: desktop (blue) versus mobile (vermilion) :srcset: /auto_examples/03_trees/images/sphx_glr_plot_04_contrast_tree_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none pattern supp[desktop] ... log2_ratio p_value 0 cart 0.393124 ... 0.650178 3.822731e-09 1 product → cart 0.313901 ... 0.721760 3.605202e-08 2 checkout 0.263079 ... 0.759139 3.089071e-07 3 cart → checkout 0.263079 ... 0.759139 3.089071e-07 4 product → cart → checkout 0.207773 ... 0.844087 1.471497e-06 5 payment 0.200299 ... 0.732833 3.055575e-05 6 checkout → payment 0.200299 ... 0.732833 3.055575e-05 7 cart → checkout → payment 0.200299 ... 0.732833 3.055575e-05 [8 rows x 5 columns] .. GENERATED FROM PYTHON SOURCE LINES 24-26 Conversion: converted versus lost visitors ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: Python plot_sunburst(db, max_depth=3, color_by="contrast", groups=db.attributes["converted"].map({True: "converted", False: "lost"}), positive="converted", title="converted (blue) versus lost (vermilion) visitors") plt.show() .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_04_contrast_tree_002.png :alt: converted (blue) versus lost (vermilion) visitors :srcset: /auto_examples/03_trees/images/sphx_glr_plot_04_contrast_tree_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.581 seconds) .. _sphx_glr_download_auto_examples_03_trees_plot_04_contrast_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_04_contrast_tree.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_contrast_tree.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_contrast_tree.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_contrast_tree.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_