A summary in a few patterns: MDL#

Instead of hundreds of frequent sequences, the Minimum Description Length principle picks the few that compress the data best (Krimp, SQS: Tatti & Vreeken, 2012). Every sequence is covered greedily by the selected patterns; the cover plot shows which runs of each day each pattern explains.

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_cover

db = sv.datasets.make_daily_routines(300, random_state=0)
summary = sv.mdl_summary(db, min_support=0.1, max_length=8, max_patterns=12)
print(f"{len(summary.patterns)} patterns, description length {summary.compression:.0%} of the singleton code")
print(summary.to_frame())
plot_cover(db, summary, max_sequences=40, max_length=15)
MDL cover by 8 patterns (description length 76% of singletons)
8 patterns, description length 76% of the singleton code
                                             pattern  support  usage  size
0  lunch → work → commute → gym → dinner → tv → s...       49     18     7
1                             lunch → work → commute      144     81     3
2  shower → commute → work → meeting → lunch → wo...       41     10     8
3         work → commute → gym → dinner → tv → sleep       53     28     6
4  wake up → coffee → work → meeting → work → lun...       36     36     8
5  wake up → coffee → shower → commute → work → m...       42     42     7
6  wake up → coffee → work → meeting → work → lun...       41      5     7
7  wake up → run → shower → coffee → breakfast → ...       41     41     7

<Axes: title={'left': 'MDL cover by 8 patterns (description length 76% of singletons)'}, xlabel='position'>

Parameter study: how many patterns#

for k in (2, 5, 10, 20):
    s = sv.mdl_summary(db, min_support=0.1, max_length=8, max_patterns=k)
    print(f"{k:2d} patterns allowed: compression {s.compression:.2f}")
plt.show()
 2 patterns allowed: compression 0.93
 5 patterns allowed: compression 0.90
10 patterns allowed: compression 0.77
20 patterns allowed: compression 0.73

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

Gallery generated by Sphinx-Gallery