Word trees around a pivot#

A double tree puts one event in the middle and grows two trees from it: the steps that follow its first occurrence (right) and those that precede it (left, read backwards). Font size and line width encode the number of sequences. It is the view of choice for questions like what happens before and after a visitor adds something to the cart? — and works just as well for melodies.

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_double_tree
shop = sv.datasets.make_customer_journeys(1000, random_state=0)
plot_double_tree(shop, "cart", max_depth=3, min_count=15)
double tree around cart (320 sequences)
<Axes: title={'left': 'double tree around cart (320 sequences)'}>

Melodies: what surrounds the motif “E D C”?#

songs = sv.datasets.load_melodies("phrase")
plot_double_tree(songs, "E D C", max_depth=3, min_count=1, top_children=4)
double tree around E → D → C (17 sequences)
<Axes: title={'left': 'double tree around E → D → C (17 sequences)'}>

Parameter study: a longer pivot#

plot_double_tree(shop, "product cart", max_depth=2, min_count=10)
plt.show()
double tree around product → cart (320 sequences)

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

Gallery generated by Sphinx-Gallery