"""
Matrices of a pattern set
=========================

The pattern–sequence incidence matrix :math:`\\mathbf{T}` (patterns in rows,
supporting sequences in columns) is the data behind the transaction map. Seriated
by hierarchical clustering, its blocks are groups of patterns supported by the
same traces. The seriated similarity matrix with its dendrogram shows the same
groups as a square heatmap.
"""

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_incidence, plot_similarity_matrix

db = sv.datasets.make_alarm_cascades(600, random_state=0)
ps = sv.mine(db, 0.08, max_length=4)
plot_incidence(ps, top=40)
plot_similarity_matrix(ps, "transaction", top=40)
# %%
# Content instead of co-occurrence
# --------------------------------
# The longest-common-subsequence similarity groups patterns that *look* alike.
plot_similarity_matrix(ps, "content", top=40)
plt.show()
