Chapter 7
Matrices, maps and sets
A pattern set has more structure than its extension tree: patterns are supported by overlapping sets of cases, they can be split into rules, they are ordered by containment, and they can be scored by interestingness measures. This chapter draws these structures as matrices (incidence, similarity, grouped rules), as points in the plane of two measures, as a terrain of pattern families, as a lattice, and as intersections of supporting sets. The pattern landscape is new.
7.1 Problem and idea
The network-based maps of chapter 4 compress the similarities of the patterns into two coordinates, and the compression costs accuracy. The matrices behind them can be drawn directly: the pattern–sequence incidence matrix, a pattern–pattern similarity matrix, or a matrix of rules. Matrix views do not overlap and scale to dense relations [73], but their message depends entirely on the order of the rows and columns, the problem of seriation [72]. Other questions call for other pictures. Which patterns are interesting rather than merely frequent is a question about measures, best answered by a scatter plot [64]; which patterns contain which is a question about an order, answered by a Hasse diagram; which patterns occur in the same cases is a question about sets, answered by an UpSet plot [67].
7.2 Theory
7.2.1 Incidence and similarity matrices
The incidence matrix of section 4.2.3 has a row per pattern and a column per sequence. Its rows are ordered by the leaf order of a hierarchical clustering of the patterns (average linkage on with the Jaccard similarity , with optimal leaf ordering), its columns by the first pattern that each sequence supports. Blocks of the seriated matrix are groups of patterns supported by the same sequences; a row that spans several blocks is a pattern shared by several groups. The square similarity matrix , seriated in the same way and shown with its dendrogram, displays the same groups without the sequences. Any similarity of the book can be used: transaction (Jaccard of supports), confidence (eq. (4.1)), content (longest common subsequence) or a fused one.
7.2.2 Sequential rules and the grouped matrix
Splitting a pattern between two of its elements gives a sequential rule with antecedent and consequent . Its confidence and lift are
| (7.1) |
the share of the cases containing in which follows, and the ratio of this share to the frequency of alone. Rules of this kind, read from frequent sequences, have been used for sequence prediction [37] and for alarm suppression [2]. The grouped matrix of Hahsler and Karpienko puts antecedents in the columns and consequents in the rows of a balloon plot, balloon area proportional to the support and color to a measure [65, 66]; spmviz orders both axes by the total support of their rules, so that the strongest rules gather in the upper left corner.
7.2.3 Measure scatter plots
Every pattern is a point in the plane of two measures — relative support and confidence, confidence and lift, support and length — and a thin line joins each pattern to its parent, so that the extension tree is still visible [64]. Frequent but unsurprising patterns sit at the right, rare but confident ones at the top left; lift separates real dependencies from coincidences of frequent events. Color can show the start event, the length or a group contrast.
7.2.4 Pattern landscapes
Maps of several hundred patterns are crowded, and the eye looks for regions rather than points. The pattern landscape turns a map into a terrain. Given coordinates of the patterns, from the transaction map for instance, it draws the support-weighted Gaussian kernel density
| (7.2) |
as contour levels, with the bandwidth chosen by Scott’s rule or by the analyst. Families of frequent patterns that occur in the same cases become mountains, isolated combinations remain in the plains, and every peak is named after the most supported long pattern near it. The landscape inherits the distortions of the map below it but makes its clusters and their weight visible at once.
7.2.5 Lattices and set views
Containment orders the frequent sequences. Their Hasse diagram has an edge whenever has one item more than and contains it, wherever the item is inserted; drawn with one row per length and the closed patterns ringed, it shows how the pattern set is built from short patterns and where the support stops changing. The lattice is denser than the extension tree, in which every pattern has a single parent, so it is drawn for a few levels and the most supported patterns of each.
The supporting sets of the patterns can also be compared as sets. The UpSet plot [67] lists the intersections of the supporting sets of a few patterns as rows of a dot matrix, with a bar for the number of sequences in each exact intersection and a bar for the support of each pattern. It answers a question that no map answers exactly: in how many cases do these patterns occur together, and in how many alone?
In a nutshell: Matrices, maps and sets
- Seriated incidence and similarity matrices show groups of patterns supported by the same cases.
- The grouped rule matrix draws antecedents against consequents, with support and lift or confidence.
- Measure scatter plots separate interesting patterns from merely frequent ones.
- Pattern landscapes turn a map into a terrain of pattern families.
- The lattice shows the containment order, the UpSet plot the overlaps of the supporting sets.
7.3 Using it in spmviz
plot_incidence(ps) and plot_similarity_matrix(ps, similarity) draw the seriated matrices, seriate(S) returns the order; ps.incidence() is the sparse matrix and networks.similarity_matrix(ps, name) any of the similarities. ps.rules(min_confidence) (or sequential_rules) returns the rules as a data frame with confidence and lift, and plot_rules_matrix(rules) draws the grouped matrix. measures.pattern_measures(ps) computes support, confidence, cumulative confidence, lift, leverage, number of children and, optionally, entropy and timing for every pattern, and plot_pattern_scatter(ps, x, y) draws any two of them. plot_landscape(ps, similarity) draws the landscape (embedding.landscape returns the density grid); plot_lattice and plot_upset draw the set views, and networks.pattern_lattice returns the Hasse diagram as a graph.
7.4 Examples
Matrices of the alarm floods. Figure 7.1 is the seriated incidence matrix of the 40 most supported frequent sequences of the synthetic alarm floods of section 4.5: the four cascades appear as four blocks of rows supported by largely disjoint sets of floods; the floods with two cascades link the blocks. The seriated transaction similarity (fig. 7.2) shows the same blocks; the content similarity (fig. 7.3) groups patterns by their events rather than by their cases.
plot_incidence(ps, top=40) plot_similarity_matrix(ps, "transaction", top=40)
Open in ColabExample plot_01_incidence_similarity.py in the gallery
Rules. The rules of confidence at least 0.6 of the alarm floods (fig. 7.4) pair every alarm with the operator action that ends its cascade: has confidence 1 and lift 2.99, confidence 1 and lift 3.0. Figure 7.5 colors the same balloons by confidence.
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)
Interesting patterns of the click-stream. Figure 7.6 places the 241 frequent sequences of the click-stream in the plane of relative support and confidence; fig. 7.7 in the plane of confidence and lift. The patterns with the highest lift are repetitions of Your situation and the pair : rare services that, once visited, are visited again or followed by a specific next one.
plot_pattern_scatter(ps, "rel_support", "confidence", labels=10) plot_pattern_scatter(ps.filter(min_length=2), "confidence", "lift", color_by="start", labels=8)
Open in ColabExample plot_03_measure_scatter.py in the gallery
A landscape. The transaction map of the alarm floods becomes the landscape of fig. 7.8: four mountains named after their longest patterns, one per cascade. Figure 7.9 varies the bandwidth.
plot_landscape(ps, similarity="transaction", peaks=5)
Lattice and UpSet. Figure 7.10 is the containment lattice of the daily-routine patterns up to length four, nine patterns per level, closed patterns ringed. The UpSet plot of the seven most supported patterns of length at least two (fig. 7.11) shows how often they occur together in the same day.
plot_lattice(ps, max_length=4, top_per_level=9) plot_upset(ps.filter(min_length=2), top=7)
Open in ColabExample plot_05_lattice_upset.py in the gallery