Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Where does the process branch? The continuation-entropy tree#
A new view: the prefix tree of web-shop journeys colored by the entropy of what comes next at every node, \(H=-\sum_e P(e\mid\text{prefix})\log_2 P(e\mid\text{prefix})\) (the end of the journey included). Green nodes have a predictable next step, vermilion nodes are decision points where visitors scatter. For process monitoring the vermilion nodes are where an early warning or a nudge pays off.
import matplotlib.pyplot as plt
import spmviz as sv
from spmviz.viz import plot_prefix_tree
db = sv.datasets.make_customer_journeys(1000, random_state=0)
plot_prefix_tree(db, max_depth=4, min_count=25, color_by="entropy",
title="continuation entropy of the web-shop journeys")

<Axes: title={'left': 'continuation entropy of the web-shop journeys'}>
The numbers behind the colors#
ps = sv.mine(db, 0.05, max_gap=1, max_length=4)
ct = sv.measures.continuation_table(ps)
print(ct.sort_values("entropy", ascending=False).head(8)[["pattern", "entropy", "top_next"]])
pattern ... top_next
40 home → category → product ... cart (0.29), exit (0.25), reviews (0.21)
15 category → product ... cart (0.27), exit (0.25), reviews (0.23)
64 search → product → reviews → product ... cart (0.33), reviews (0.24), search (0.16)
7 product ... cart (0.28), exit (0.26), reviews (0.24)
28 reviews → product ... cart (0.34), reviews (0.26), exit (0.16)
48 product → reviews → product ... cart (0.34), reviews (0.26), exit (0.16)
42 home → search → product ... exit (0.27), cart (0.27), reviews (0.26)
30 search → product ... cart (0.28), reviews (0.28), exit (0.26)
[8 rows x 3 columns]
Parameter study: history length#
Does a longer history make the next page more predictable? Mean entropy by prefix length:
ct["length"] = ps.lengths
print(ct.groupby("length")["entropy"].mean().round(2))
plt.show()
length
1 1.08
2 1.00
3 1.05
4 0.94
Name: entropy, dtype: float64
Total running time of the script: (0 minutes 0.692 seconds)