"""
Case study: the UWV unemployment-benefit application
====================================================

The clickstream of the paper, read as a story. Where do applicants start, which
service sequences are typical, where do they hesitate, and which steps are
predictable?
"""

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_prediction, plot_prefix_tree, plot_sankey, plot_transition_graph

db = sv.datasets.load_clickstream()
ps = sv.mine(db, 0.01, algorithm="cmspam", max_gap=1, max_length=10)

# %%
# The paths of the first steps
# ----------------------------
plot_sankey(db, max_steps=5, top=6)

# %%
# The transition graph of the services
# ------------------------------------
plot_transition_graph(db, top_edges=26, labels=None)

# %%
# Predictability of the next service
# ----------------------------------
plot_prefix_tree(db, max_depth=4, min_count=12, color_by="entropy")

# %%
# What comes next after "Your last employer → The dismissal"?
# ------------------------------------------------------------
obs = [0, 1]  # Your last employer, The dismissal
print(sv.predict_next(ps, obs))
plot_prediction(ps, obs)
plt.show()
