Benchmark databases of sequential pattern mining#

The databases distributed with SPMF (Fournier-Viger et al., 2016) are the common yardstick of the literature: SIGN (sign language), LEVIATHAN and BIBLE (text), BMS1/BMS2, FIFA and KOSARAK (click streams), BIKE (bike stations), MSNBC (page categories). fetch_spmf() downloads and caches them. Here SIGN is mined and drawn; the book reports run times on all of them.

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_nbvfs, plot_sunburst

print(sv.datasets.benchmark_table()[["name", "sequences", "items", "avg_length"]])
try:
    db = sv.datasets.fetch_spmf("SIGN")
except OSError as exc:  # no network: fall back to a synthetic database of the same size
    print("download failed:", exc)
    db = sv.datasets.make_quest(730, n_items=267, avg_elements=52, avg_itemset=1.0, random_state=0)
print(db.stats())
ps = sv.mine(db, min_support=0.5, max_length=5)
print(ps)
         name  sequences    items  avg_length
0       BIBLE      36369  13905.0       21.60
1        BMS1      59601    497.0        2.42
2        BMS2      77512   3340.0        4.62
3        FIFA      20450   2990.0       34.74
4  KOSARAK10K      10000      NaN         NaN
5   LEVIATHAN       5834   9025.0       33.80
6       MSNBC      31790     17.0       13.23
7        SIGN        730    267.0       52.00
8        BIKE      21078     67.0        7.27
n_sequences             730.000000
n_items                 267.000000
n_elements            37958.000000
avg_length               51.997260
min_length               18.000000
max_length               94.000000
avg_itemset_size          1.000000
avg_distinct_items       51.997260
density                   0.194746
dtype: float64
PatternSet(n_patterns=173, algorithm='cmspam', min_support=0.5, n_sequences=730)

Maps of the frequent sequences#

fig, axes = plt.subplots(1, 2, figsize=(14, 6))
plot_nbvfs(sv.NBVFS("cm").fit(ps.filter(min_length=2)), ax=axes[0], legend=False, labels=10)
plot_sunburst(db, ax=axes[1], max_depth=3, min_angle=8, title="first three signs")
axes[1].get_legend().remove()
plt.show()
NBVFS-CM confidence-based MDS, first three signs

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

Gallery generated by Sphinx-Gallery