Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Sequential rules as a grouped matrix#
Splitting a pattern between two itemsets gives a rule antecedent ⇒ consequent with confidence \(\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)

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
<Axes: title={'left': 'grouped matrix of sequential rules (size: support)'}, xlabel='antecedent (left-hand side)', ylabel='consequent ⇒'>
Colored by confidence#
plot_rules_matrix(rules, color="confidence", top_antecedents=14, top_consequents=10)
plt.show()

Total running time of the script: (0 minutes 0.286 seconds)