.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_maps/plot_02_rules_matrix.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_05_maps_plot_02_rules_matrix.py: Sequential rules as a grouped matrix ==================================== Splitting a pattern between two itemsets gives a rule *antecedent ⇒ consequent* with confidence :math:`\sigma(\varphi)/\sigma(\alpha)` and lift. The grouped matrix (Hahsler & Karpienko, 2017) puts antecedents in columns and consequents in rows; balloon area is the support, color the lift. .. GENERATED FROM PYTHON SOURCE LINES 10-21 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_rules_matrix db = sv.datasets.make_alarm_cascades(600, random_state=0) ps = sv.mine(db, 0.05, max_length=4) rules = ps.rules(min_confidence=0.6) print(rules.head(8)[["rule", "support", "confidence", "lift"]]) plot_rules_matrix(rules, top_antecedents=14, top_consequents=10) .. image-sg:: /auto_examples/05_maps/images/sphx_glr_plot_02_rules_matrix_001.png :alt: grouped matrix of sequential rules (size: support) :srcset: /auto_examples/05_maps/images/sphx_glr_plot_02_rules_matrix_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none rule support confidence lift 0 S-LOLEVEL ⇒ OP-DRAIN 194 1.0 2.857143 1 S-HILEVEL2 ⇒ OP-DRAIN 191 1.0 2.857143 2 K-SURGE ⇒ OP-LOADDOWN 186 1.0 3.000000 3 P-LOWFLOW ⇒ OP-PUMPSTART 183 1.0 2.985075 4 P-LOWPRES ⇒ OP-PUMPSTART 183 1.0 2.985075 5 S-HILEVEL ⇒ OP-DRAIN 183 1.0 2.857143 6 P-TRIP ⇒ OP-PUMPSTART 180 1.0 2.985075 7 K-HITEMP ⇒ OP-LOADDOWN 179 1.0 3.000000 .. GENERATED FROM PYTHON SOURCE LINES 22-24 Colored by confidence --------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python plot_rules_matrix(rules, color="confidence", top_antecedents=14, top_consequents=10) plt.show() .. image-sg:: /auto_examples/05_maps/images/sphx_glr_plot_02_rules_matrix_002.png :alt: grouped matrix of sequential rules (size: support) :srcset: /auto_examples/05_maps/images/sphx_glr_plot_02_rules_matrix_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.237 seconds) .. _sphx_glr_download_auto_examples_05_maps_plot_02_rules_matrix.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/05_maps/plot_02_rules_matrix.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_rules_matrix.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_rules_matrix.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_rules_matrix.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_