Note
Go to the end to download the full example code or to run this example in your browser via Binder.
A spectacular sunburst: chess openings#
Two thousand games drawn from a small opening book of 33 main lines. Every game is the sequence of its first moves (plies). The sunburst stacks the moves ring by ring: the angle of a wedge is the share of games that start with that move sequence, so the familiar families — 1.e4 e5 open games, the Sicilian 1.e4 c5, the closed 1.d4 d5 and the Indian 1.d4 Nf6 systems — appear as large slices with their branches. Frequent sequences then summarize the book.
import matplotlib.pyplot as plt
import spmviz as sv
from spmviz.viz import plot_icicle, plot_sunburst
db = sv.datasets.load_chess_openings(2000, random_state=0)
plot_sunburst(db, max_depth=5, min_angle=7, title="the first five plies of 2,000 games")

<Axes: title={'left': 'the first five plies of 2,000 games'}>
The same tree as an icicle#
plot_icicle(db, max_depth=6, min_count=20, title="icicle of the opening tree")

<Axes: title={'left': 'icicle of the opening tree'}>
Frequent (contiguous) move sequences#
ps = sv.mine(db, min_support=0.05, max_gap=1)
print(ps.filter(min_length=4).sort("support").to_frame()[["pattern", "support", "confidence"]].head(10))
pattern support confidence
0 e4 → e5 → Nf3 → Nc6 468 0.924901
1 e4 → c5 → Nf3 → d6 221 0.620787
2 c5 → Nf3 → d6 → d4 194 0.877828
3 e4 → c5 → Nf3 → d6 → d4 194 0.877828
4 d4 → Nf6 → c4 → e6 190 0.567164
5 e5 → Nf3 → Nc6 → Bb5 187 0.399573
6 e4 → e5 → Nf3 → Nc6 → Bb5 187 0.399573
7 Nf3 → d6 → d4 → cxd4 156 0.804124
8 c5 → Nf3 → d6 → d4 → cxd4 156 0.804124
9 e4 → c5 → Nf3 → d6 → d4 → cxd4 156 0.804124
Parameter study: depth#
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
for ax, d in zip(axes, (2, 4, 6)):
plot_sunburst(db, ax=ax, max_depth=d, min_angle=10, title=f"depth {d}")
ax.get_legend().remove()
plt.show()

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