Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Matrices of a pattern set#
The pattern–sequence incidence matrix \(\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)
<Axes: title={'left': 'transaction similarity of 40 patterns'}>
Content instead of co-occurrence#
The longest-common-subsequence similarity groups patterns that look alike.
plot_similarity_matrix(ps, "content", top=40)
plt.show()

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

