"""
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.
"""

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)
# %%
# Colored by confidence
# ---------------------
plot_rules_matrix(rules, color="confidence", top_antecedents=14, top_consequents=10)
plt.show()
