"""
Patterns in the plane of two measures
=====================================

Every pattern is a point; the axes are two interestingness measures and grey
lines join each pattern to its parent (Stolper, Perer & Gotz, 2014). Frequent
but unsurprising patterns sit at the right, rare but confident ones at the top
left; lift separates real dependencies from coincidences.
"""

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_pattern_scatter

db = sv.datasets.load_clickstream()
ps = sv.mine(db, 0.01, max_gap=1, max_length=10)
plot_pattern_scatter(ps, "rel_support", "confidence", labels=10)
plot_pattern_scatter(ps.filter(min_length=2), "confidence", "lift", color_by="start", labels=8)
print(ps.measures().sort_values("lift", ascending=False).head(6)[["pattern", "support", "confidence", "lift"]])
plt.show()
