Chapter 1
Introduction
This chapter explains why frequent sequences need visualization, which questions the different views answer, and how an analysis proceeds from an event log to a picture that can be interpreted and shared. It introduces the network-based visualization of frequent sequences that gave rise to the book, the spmviz package, and a first session with it. The theory starts in chapter 2.
1.1 Problem and idea
An event log records what happened, in which order, and to whom: the pages a visitor opened, the alarms a plant raised and the actions its operators took, the activities of a day. Grouping the events by case (a session, a trace, a day) gives a database of sequences. Sequential pattern mining, introduced by Agrawal and Srikant [6], finds the sequences of events that occur, in this order but not necessarily consecutively, in at least a given share of the cases. Thirty years of research have made the mining fast [7, 8, 9, 10, 11] and have produced condensed representations, constraints and interestingness measures [12, 13].
The output of a mining run is a list of patterns with their supports, and the list is long. The four short sequences of the PrefixSpan paper already contain 53 frequent sequences at a support threshold of one half (section 2.6), and a real log yields hundreds at the thresholds that analysts use. The list is also redundant: every subsequence of a frequent sequence is frequent, so a single long pattern appears together with all of its prefixes and many of its subsequences. A table of patterns answers the question is this sequence frequent?, but not the questions an analyst actually has. Where does the process branch? Which sequences grow out of which? Which patterns describe the same sub-process? How do two groups of cases differ? What is likely to happen next?
Visualization addresses these questions by exploiting the structure that the patterns share. Frequent sequences form a tree under extension, they inherit their supports from each other, they are supported by overlapping sets of cases, and they can be laid back onto the sequences they were mined from. Each of these relations suggests a family of views, and the literature of visual analytics [14, 15, 16], process mining [17] and social-science sequence analysis [18, 19] has developed them largely independently of each other. The network-based visualization of frequent sequences (NBVFS) of Bántay and Abonyi [1] adds three views that make the relations between the frequent sequences themselves visible: a weighted network of extensions and two maps that place similar sequences close to each other. Figure 1.1 shows how the pieces fit together.
1.2 What visualization can and cannot tell
The views of this book are descriptive. They show which sequences are frequent and how the frequent sequences relate to each other, but frequency is not causality, and a frequent sequence of two alarms does not prove that the first causes the second. Three further limits should be kept in mind.
First, every view depends on the mining parameters. The support threshold, the gap and span constraints and the maximum length decide which patterns exist at all, and a pattern absent from a picture may only be absent from the pattern set. Chapter 2 shows how quickly the number of patterns changes with the threshold and the gap, and each example of the book ends with such a parameter study. Second, many views aggregate. A Sankey diagram or a directly-follows graph keeps only consecutive pairs and forgets the history; a sunburst keeps the history but only from the start of the sequence. The higher-order networks of chapter 6 and the word trees of chapter 5 relax these limitations, and the network-based maps of chapter 4 keep the patterns themselves as the objects of the picture. Third, maps obtained by multidimensional scaling distort distances. Their stress, reported by the package with every map, tells how much [20].
1.3 The toolbox
spmviz is a pure Python package built on NumPy, SciPy, pandas, NetworkX and Matplotlib [21, 22, 23, 24]. Its modules follow the workflow of fig. 1.1:
- data: SequenceDatabase reads event tables, SPMF files, XES logs and pm4py objects, and PatternSet holds patterns with their supports and supporting sequences (spmviz.data, spmviz.patterns, spmviz.io);
- mining: PrefixSpan, SPAM, CM-SPAM, SPADE and GSP with gap, span and time constraints, closed, maximal and generator patterns, top- mining, sequential rules, episodes, and adapters to the prefixspan, seq2patand gsppypackages and to SPMF [25, 26, 27, 28] (spmviz.mining, spmviz.backends);
- structure: measures, similarities, extension networks, prefix trees, transition graphs, higher-order networks, communities, embeddings, MDL summaries and next-event prediction (spmviz.measures, spmviz.networks, spmviz.embedding, spmviz.summary, spmviz.predict);
- views: the NBVFS estimator, nearly forty static views in spmviz.viz and interactive twins in spmviz.interactive.
The package bundles the two real logs of the NBVFS paper, the anonymized alarm log of an alkylation plant and a click-stream excerpt of the BPI Challenge 2016 [29], small textbook databases, a public-domain melody collection and a chess-opening book, generators of synthetic data with known structure, and a downloader for the benchmark databases distributed with SPMF.
1.4 A first session
The click-stream of the NBVFS paper serves as the running example of the book: 343 sessions of applicants for unemployment benefit on the portal of the Dutch Employee Insurance Agency, over 14 services coded 0–13. Mining it as in the paper and drawing the extension network of the sessions that start with service 2 (Hours worked) takes four lines:
import spmviz as sv db = sv.datasets.load_clickstream() # 343 sessions, 14 services ps = sv.mine(db, min_support=0.01, max_gap=1, max_length=10) print(ps) # PatternSet(n_patterns=241, algorithm=’cmspam’, ...) wn = sv.NBVFS("wn", start_items=[2]).fit(ps) # weighted extension network wn.plot() # wn.graph_ is a networkx.DiGraph sv.predict_next(ps, [0, 1]) # after "Your last employer -> The dismissal": The dismissal (0.45), ...
The pattern set keeps every pattern with its support and the identifiers of its supporting sequences; it can be filtered, condensed (ps.closed() leaves 219 of the 241 patterns, ps.maximal() 53), turned into a table (ps.to_frame()) or a graph (ps.to_networkx()), and drawn by every view of the book.
1.5 How the book is organized
Chapter 2 defines sequences, containment, support and constraints, the condensed representations of a pattern set, the extension tree and its confidences, and the five mining algorithms of the package. Chapter 3 surveys the visualizations of frequent sequences proposed in the literature and arranges them by the relation they draw and the question they answer. Chapter 4 develops the network-based views of Bántay and Abonyi and extends them with fused similarities and community-based segmentation. Chapter 5 presents trees of prefixes and patterns, among them two new views, the continuation-entropy tree and the contrast sunburst. Chapter 6 covers flows and transitions, from Sankey diagrams to pattern-induced higher-order networks. Chapter 7 treats matrices, maps and set views, including pattern landscapes. Chapter 8 returns to the sequences themselves: index plots, chronograms, dotted charts, sequence logos, arc diagrams, episodes and summaries by the minimum description length principle. Chapter 9 shows how data enter and results leave the package, and chapter 10 reports benchmarks and two case studies. Chapter A lists the application programming interface, chapter B maps the scripts of the original paper to the package, and chapter C catalogues the example scripts.
1.6 Further reading
The surveys of Mooney and Roddick [12] and of Fournier-Viger and co-authors [13] cover the algorithms of sequential pattern mining. Guo and co-authors [14] and Yeshchenko and Mendling [15] survey the visual analysis of event sequences, and Jentner and Keim [16] the visualization of patterns. Van der Aalst’s textbook [17] is the standard reference of process mining, and Gabadinho and co-authors [18] describe the sequence-analysis tradition of the social sciences and its R package TraMineR.