Mining and Visualizing Frequent Sequences in PythonThe spmviz toolbox

Appendix A
API reference

This appendix lists every public class and function of spmviz, module by module, with the first sentence of its docstring. The lists are generated from the __all__ attribute of each module by book/build_api_appendix.py, so they are complete by construction; the full signatures, parameters, and attributes are in the online documentation and in the docstrings (help(spmviz.NBVFS)). The conventions of the API are described in sections 2.5 and 4.3, the notation of the docstrings in table 2.1.

A.1 spmviz.data: Sequence databases and patterns

Name

Kind

Description

Constraints

class

Gap and span constraints of an occurrence

SequenceDatabase

class

A database of sequences of itemsets with optional timestamps and attributes

as_pattern

function

Normalize a pattern given as tuple of tuples, list or string

contains

function

Whether a sequence contains a pattern under the given constraints

find_occurrence

function

Element indices of the earliest-ending occurrence of a pattern, or None

format_pattern

function

Format a pattern as text

is_subpattern

function

Whether pattern p is contained in pattern q (no gap constraints)

item_key

function

Sort key giving a total order over mixed items: numbers first, then strings

parent_pattern

function

The pattern with its last item removed (the empty tuple for single items)

pattern_items

function

Items of a pattern in order of appearance (with repetitions)

pattern_length

function

Number of items of a pattern

A.2 spmviz.patterns: Pattern sets

Name

Kind

Description

PatternSet

class

Frequent sequential patterns with their supports and supporting sequences

A.3 spmviz.mining: Mining algorithms

Name

Kind

Description

ALGORITHMS

constant

Names of the built-in mining algorithms

EpisodeSet

class

Frequent episodes with WINEPI frequencies and minimal occurrences

closed_mask

function

Boolean mask of the closed patterns of a pattern set

cmspam

function

Mine frequent sequential patterns with CM-SPAM (bitmaps + co-occurrence pruning)

generator_mask

function

Boolean mask of the generator patterns of a pattern set

gsp

function

Mine frequent sequential patterns with GSP (Apriori-style, any constraint)

maximal_mask

function

Boolean mask of the maximal patterns of a pattern set

mine

function

Mine frequent sequential patterns

mine_episodes

function

Frequent serial or parallel episodes of one event stream

prefixspan

function

Mine frequent sequential patterns with PrefixSpan

sequential_rules

function

Rules antecedent ⇒ consequent from every split of every pattern

spade

function

Mine frequent sequential patterns with SPADE (vertical id-lists)

spam

function

Mine frequent sequential patterns with SPAM (bitmaps, Apriori candidate pruning only)

topk

function

The k most frequent patterns (ties at the k-th support kept)

A.4 spmviz.backends: External back ends

Name

Kind

Description

available

function

Which external back ends can be used in this environment

run

function

Run an external miner and return a PatternSet (called by mine)

spmf_command

function

The SPMF command line for an algorithm

A.5 spmviz.measures: Measures, continuations, contrasts, similarities

Name

Kind

Description

END

constant

Token of the end of a sequence in continuation tables and trees

content_similarity

function

Similarity of the patterns themselves (their item strings)

continuation

function

Distribution of the element that follows an occurrence of a pattern

continuation_entropy

function

Entropy (bits) of the continuation distribution of a pattern

continuation_table

function

Continuation statistics of every pattern: entropy, normalized entropy, most likely next items

contrast

function

Support of every pattern in two or more groups of sequences

entropy

function

Shannon entropy (bits) of a probability vector or a pandas Series

pattern_counts

function

Number of all, closed and maximal patterns for a range of minimum supports

pattern_measures

function

Interestingness measures of every pattern

time_statistics

function

Span and gaps of the earliest occurrence of every pattern in every supporting sequence

transaction_similarity

function

Similarity of the supporting sequence sets of every pair of patterns

A.6 spmviz.networks: Graphs of sequences and patterns

Name

Kind

Description

START

constant

Token of the start of a sequence in transition graphs

confidence_matrix

function

Confidence adjacency 𝐀: aij is the weight of the extension φi →φj

double_tree

function

Predecessor and successor trees of a pivot pattern (word tree / double tree)

extension_network

function

Weighted extension network of frequent sequences (NBVFS-WN)

higher_order_network

function

Variable-order network of the sequences (BuildHON; Xu, Wickramarathne and Chawla, 2016)

item_graph

function

Items as nodes, a → b weighted by the support of the 2-pattern ⟨a b⟩ (eventually-follows)

pattern_communities

function

Groups of patterns that tend to occur in the same sequences (sub-processes)

pattern_lattice

function

Hasse diagram of the containment order: p → q when q has one item more and contains p

prefix_tree

function

Trie of the sequences (the aggregation behind sunbursts, icicles, LifeFlow and word trees)

similarity_graph

function

Undirected graph of similar patterns (kNN and/or threshold on a similarity)

similarity_matrix

function

A pattern similarity by name: "transaction" (Jaccard), "confidence" (closure), "content" (LCS), or a precomputed square array

sublogs

function

The sequences supporting the patterns of each group: one sub-database per community

transition_graph

function

Directly-follows graph (first-order transitions; process mining DFG, Markov chain)

transitive_confidence

function

Max-product transitive closure 𝐀∗ (NBVFS-CM)

A.7 spmviz.embedding: Embeddings, fusion and landscapes

Name

Kind

Description

align

function

Rotate/reflect and center Y to best match reference (orthogonal Procrustes)

classical_mds

function

Classical (Torgerson–Gower) scaling of a dissimilarity matrix

fuse_similarities

function

Combine pattern similarities: weighted "mean", "min", "max", "product" or "snf"

landscape

function

Weighted Gaussian kernel density of a 2-D map

mds

function

Embed a dissimilarity matrix; returns (Y, stress)

smacof

function

Metric MDS by majorization (SMACOF)

snf

function

Similarity network fusion of several similarity matrices (values in [0, 1])

A.8 spmviz.layout: Layouts

Name

Kind

Description

layered_layout

function

Layered (Sugiyama-style) layout with barycentric crossing reduction

radial_tree_layout

function

Concentric layout: the root in the center, depth d on the circle of radius d

tree_layout

function

Layered tree layout (tidy): leaves on a line, parents centered over their children

A.9 spmviz.nbvfs: NBVFS maps

Name

Kind

Description

NBVFS

class

Network-based visualisation of frequent sequences (WN, CM, TM and fused maps)

A.10 spmviz.summary: MDL summaries

Name

Kind

Description

MDLSummary

class

Result of mdl_summary

mdl_summary

function

Greedy MDL selection of contiguous patterns

A.11 spmviz.predict: Next-event prediction

Name

Kind

Description

match_context

function

Longest suffix of observed that is a pattern of ps with at least min_children extensions

predict_next

function

Most likely next events after an observed partial sequence

A.12 spmviz.viz: Static visualizations

Name

Kind

Description

BRAND

constant

Pannon blue of the figures (#285780)

CATEGORICAL

constant

Categorical palette of the item colors

OKABE_ITO

constant

The Okabe–Ito color-blind-safe palette

db_colors

function

Colors of the items of a database (most frequent first), keyed by label or item

embed_patterns

function

Coordinates of the patterns from a similarity (name, matrix, or a list of them to fuse)

item_colors

function

Stable item → color mapping

plot_arc_diagram

function

Arc diagram of the repeated subsequences of one long sequence (Wattenberg, 2002)

plot_chord

function

Chord diagram of the transitions between the top most frequent events

plot_communities

function

Pattern communities (Louvain) on the MDS map, with convex hulls and representative patterns

plot_cover

function

Cover of the sequences by the patterns of an MDL summary

plot_dotted_chart

function

Dotted chart: every event a dot at (time, sequence), colored by event

plot_double_tree

function

Word tree in both directions around a pivot event or pattern

plot_embedding

function

2-D map of the patterns from any similarity (or a fused list of similarities)

plot_episode_timeline

function

Minimal occurrences of the most frequent serial episodes on the time axis

plot_explosion

function

Number of all, closed and maximal patterns against the minimum support

plot_gap_distribution

function

Box plots of the time span (or the gaps) of the occurrences of the top patterns

plot_growth_sankey

function

How support splits when frequent sequences grow (support flows of the extension network)

plot_hon

function

Pattern-induced higher-order network (memory nodes around their first-order event)

plot_icicle

function

Icicle plot of the prefix tree (CoreFlow/LifeFlow style)

plot_incidence

function

Pattern–sequence incidence matrix 𝐓 with seriated rows and columns

plot_landscape

function

Pattern landscape: support-weighted density of the MDS map as a terrain with labeled peaks

plot_lattice

function

Hasse diagram of the containment order, one row per pattern length

plot_matrixwave

function

MatrixWave-style sequence of transition matrices between consecutive steps

plot_nbvfs

function

Draw a fitted NBVFS map

plot_nbvfs_cm

function

Fit and draw the confidence-based MDS map (NBVFS-CM); start_items highlights trees

plot_nbvfs_tm

function

Fit and draw the transaction-based MDS map (NBVFS-TM)

plot_nbvfs_wn

function

Fit and draw the weighted extension network (NBVFS-WN) of a pattern set

plot_overview

function

Six linked views of one mining run: sunburst of the raw sequences, NBVFS-WN, NBVFS-TM, transition graph, sequence index plot with the top pattern, and the suppo

plot_pattern_scatter

function

Patterns as points in the plane of two measures, linked to their parents

plot_patterns

function

Glyph table of the best patterns: events as colored tiles, measures as bars

plot_prediction

function

Prediction fan: the observed events, the matched frequent context, and the ranked continuations

plot_prefix_tree

function

Node-link prefix tree with edges as wide as the number of sequences passing

plot_rules_matrix

function

Grouped matrix of sequential rules: antecedents in columns, consequents in rows

plot_sankey

function

Alluvial diagram of the first steps of the sequences

plot_sequence_frequency

function

The most frequent complete sequences, bar height proportional to their frequency

plot_sequence_index

function

Sequence index plot: one row per sequence, one colored cell per element

plot_sequence_logo

function

Sequence logo of the events around an anchor (or of the first positions)

plot_similarity_matrix

function

Seriated heatmap of a pattern similarity with its dendrogram

plot_state_distribution

function

Chronogram: distribution of the events at every position, with the cross-sectional entropy

plot_sunburst

function

Sequences sunburst: depth on rings, angle proportional to the number of sequences

plot_transition_graph

function

Directly-follows graph: node size = occurrences, edge width = transitions, color = probability

plot_transition_matrix

function

Heatmap of first-order transition counts or probabilities (normalize="row", None)

plot_upset

function

UpSet plot of the supporting sequences of the top patterns

seriate

function

Order of rows/columns that places similar items next to each other (hierarchical clustering)

tree_data

function

The tree behind the tree views: a prefix tree of a database or the pattern tree of a pattern set

A.13 spmviz.interactive: Interactive figures

Name

Kind

Description

embedding_figure

function

Interactive 2-D map of the patterns from a similarity

icicle_figure

function

Zoomable icicle of the sequence prefixes

nbvfs_figure

function

Interactive version of a fitted NBVFS map (hover shows the measures)

network_figure

function

Plotly drawing of any networkx graph (coordinates from x/y or a spring layout)

sankey_figure

function

Interactive Sankey diagram of the first steps ("$" = the sequence ended)

sunburst_figure

function

Zoomable sunburst of the sequence prefixes (click a wedge to zoom in)

to_pyvis

function

A pyvis network (vis.js) of a graph: drag nodes, zoom, hover tooltips

treemap_figure

function

Treemap of the sequence prefixes

A.14 spmviz.io: Import and export

Name

Kind

Description

from_igraph

function

Convert a python-igraph graph back to networkx (name becomes the node key)

read_graph

function

Read a graph written by write_graph (GEXF, GraphML, GML, JSON, Cytoscape JSON, CSV)

read_patterns

function

Read a pattern set written by write_patterns or by SPMF (#SUP/#SID lines)

read_spmf

function

Read a sequence database in SPMF format

read_xes

function

Read an XES event log (IEEE 1849) without external dependencies

to_cytoscape

function

Cytoscape.js / Cytoscape desktop JSON with node positions

to_igraph

function

Convert to a python-igraph graph (node name in the name attribute)

write_graph

function

Write a graph with all node and edge attributes (format from the extension)

write_patterns

function

Write a pattern set; the format follows the extension

write_spmf

function

Write a database in SPMF format

write_xes

function

Write a database as an XES event log (one trace per sequence, one event per item)

A.15 spmviz.datasets: Data sets

Name

Kind

Description

SPMF_BENCHMARKS

constant

Metadata and download locations of the SPMF benchmark databases

benchmark_table

function

The benchmarks known to fetch_spmf with their published statistics

fetch_spmf

function

Load a benchmark sequence database (downloaded once, then read from the cache)

get_data_home

function

Cache directory of the downloaded benchmarks (created when missing)

load_agrawal_srikant

function

The customer-sequence example of Agrawal and Srikant (1995), Mining sequential patterns

load_alarm_log

function

Alarm and operator-action log of an industrial hydrofluoric-acid alkylation plant

load_chess_openings

function

Synthetic chess games drawn from a small opening book of 33 main lines

load_clickstream

function

Click sessions on a web portal of the Dutch Employee Insurance Agency (UWV)

load_melodies

function

Melodies of 13 well-known public-domain songs as note sequences

load_prefixspan_example

function

The four-sequence example database of the PrefixSpan paper (Pei et al., 2001/2004)

make_alarm_cascades

function

Alarm floods made of interleaved cascades of parallel sub-processes

make_customer_journeys

function

Visitor journeys in an online shop, with funnels, loops and abandonment

make_daily_routines

function

Morning-to-evening routines of three personas: early birds, commuters and remote workers

make_planted_patterns

function

Random sequences with planted patterns (ground truth in the attributes)

make_quest

function

IBM Quest-style synthetic sequences of itemsets (Agrawal and Srikant, 1995)