Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Transition graphs, matrices and MatrixWave#
The directly-follows graph of process mining (van der Aalst, 2016) counts consecutive pairs: a first-order summary that is easy to read but forgets the history. The same information as a row-normalized transition matrix, and as a MatrixWave-style sequence of step-by-step matrices (Zhao et al., 2015).
import matplotlib.pyplot as plt
import spmviz as sv
from spmviz.viz import plot_matrixwave, plot_transition_graph, plot_transition_matrix
db = sv.datasets.make_customer_journeys(1000, random_state=0)
plot_transition_graph(db, top_edges=24)
G = sv.networks.transition_graph(db) # networkx.DiGraph with counts and probabilities
print(G["product"]["cart"])

{'count': 273, 'probability': 0.2932330827067669, 'n_sequences': 254, 'weight': 273.0}
Transition matrix#

<Axes: title={'left': 'transition matrix'}, xlabel='to', ylabel='from'>
MatrixWave: one matrix per step#
plot_matrixwave(db, steps=3, top=6)

<Figure size 900x340 with 3 Axes>
Parameter study: the frequency filter#
fig, axes = plt.subplots(1, 2, figsize=(14, 5))
for ax, k in zip(axes, (10, 40)):
plot_transition_graph(db, ax=ax, top_edges=k, labels=None, title=f"{k} strongest transitions")
plt.show()

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