Chapter 31 Instructor Notes: Chess Database Analytics

Chapter text · Case study 1 · Case study 2 · Exercises · Quiz · Key takeaways

This is the Analyst Track's home chapter and the one later chapters quietly depend on: outpost/database.py is the query engine that Chapters 32, 35 and 40 reuse. The chapter's title promises "10 million games", and the hook's first act is to correct it — 4,471,751 games, plus puzzles. Use that correction as the tone for the whole session: a database analyst who cannot say exactly what was mined has already lost the argument. The second act of the hook is the chapter in miniature: a raw score (Scotch 54.6%) becomes a rating-adjusted score (+4.2), and then an explanation once you query a position (4...Nxd4 is a popular club mistake).

Dev appears in the hook and the Project Checkpoint. Remind the class once:

🎭 Dev's games are real Lichess games played by anonymous players at his rating, assembled into one "player" so the method can be shown. Nothing about him is a fact about a real person.

Learning objectives

The chapter frames itself as "the questions, the filters and the checks you put between the data and your conclusion". By the end, students should be able to:

  1. State exactly what a database contains — sources, window, counts — and what it is not (the Lichess sample is 34.2 hours of one Thursday and Friday, not a year or a panel).
  2. Treat every filter as an assumption and show what each one does to the headline numbers (bots, engine and online events, unbalanced pairings).
  3. Compare openings by rating-adjusted score in balanced games, and explain what adjustment does not remove (style, preparation, time-control mix, noisy ratings).
  4. Query positions, not names: build a prefix index, find transpositions, and validate a new query engine against a known table before trusting it.
  5. Use sample weights and Kish effective n for the move-text subset, and recognise self-selection ("analysed games only") that weights cannot fix.
  6. Read heat maps and conversion tables sceptically: frequency is not quality, the definition is the finding, and end-of-game clock statistics suffer reverse causality.
  7. Run a split-half replication before believing a mined table, and expect the extremes to shrink.

Timing plan

75-minute session

Minutes Activity Notes
0–8 Hook: "ten million games" and the Scotch Ask the class to count the snapshot before revealing 4,471,751. Vote: "Is the Scotch the best opening?"
8–18 31.2 filters The two funnels; OTB balancing raises draws 25.7% → 34.6%. The != "BOT" pitfall.
18–30 31.3 rating adjustment r = 0.74; the OTB Slav (59.4% raw, White +47 rating points, adj +4.3).
30–45 31.4 position queries Board demo below: the Scotch next-move table and 4...Nxd4. Transposition shares (QGD Exchange 70.6%).
45–55 31.7 definition is the finding 41.6 / 46.0 / 46.1 at 2400+; median eval +0.40 vs +1.80.
55–70 31.9 replication Data demo below: the 2% subsample (0 of 10 replicate).
70–75 Exit ticket

3-hour block

Minutes Activity Notes
0–15 Hook and inventory Students list what they think is in a "chess database" before seeing the source table in 31.1.
15–35 31.1–31.2 The hourly skew (mean rating 1624 → 1662 by UTC hour); the filter cascade; Try it on OTB draw rates by speed.
35–60 31.3 Lichess and OTB confounding tables; band patterns (Sicilian, Caro-Kann, French get worse for Black with level; the Italian fades).
60–95 Lab: the query engine See the lab plan under "Running the code".
95–105 Break
105–120 31.5 weights The truth test: unweighted bullet share 29.47% vs 35.90% truth vs 35.88% weighted vs 20.72% analysed only.
120–135 31.6 heat maps and 31.8 time Frequency vs quality; reverse causality in the low-clock table.
135–155 Case Study 1: three rows of one query Small groups take one row each (paper pawn, real pawn, relay glitch).
155–172 Case Study 2 and 31.9 Replication by database size; the "back-of-envelope" standard-error table.
172–180 Decision checklist, exit ticket

Key numbers and games

Item Value as quoted Where
Snapshot 4,471,751 games (4,000,000 Lichess + 373,918 broadcast rows + 97,833 master games); with 6,193,530 puzzles 10,665,281 records; move text for 864,816 Lichess games Hook; §31.1
Lichess window 1 Oct 2026 00:00 → 2 Oct 10:14 UTC (34.2 hours); mean average rating by hour 1624 (12:00) to 1662 (18:00); bullet share 32.8–38.7% §31.1
Bots Humans scored 39.0% as White (2,575) and 36.5% as Black (1,887) vs bots; 16,485 bot-vs-bot games §31.2
Unbalanced Lichess White >100 higher: 68.5% (281,961); Black higher: White 34.2% (279,119) §31.2
OTB filters Engine events 3,880 games, 50.0% draws, White 70.0%; online events 6.4% draws; balancing: draws 25.66% → 34.64%, mean avg FIDE 2033.5 → 2059.3 §31.2
Scotch (all Lichess) 54.6% [54.3–55.0], n = 80,403; expected 50.4; adj +4.2 Hook; §31.3
Confounding r(raw, expected) = 0.74 across 25 families; Lichess raw 49.9–54.6%, adj +0.2 to +4.2; OTB raw 48.9–59.4%, adj +2.0 to +4.3; OTB Slav 59.4% with White +47.2 rating points §31.3
Band patterns (balanced Lichess, White adj) Sicilian −0.4 (<1200) → +2.2 (2200–2399); Caro-Kann +0.3 → +3.5 (2400+); French +0.2 → +2.5; Italian +2.2 → +0.9; Scotch +4.7 → +2.8 §31.3
Scotch next move 4...Nxd4 43.0% of weighted Lichess replies, White 56.9% [54.7–59.2]; OTB 3.5%; SF19 after 4...Nxd4 5.Qxd4 +0.76 (d20) / +0.62 (d24); 4...Nf6 +0.10 / +0.06 Hook; Exercise B1
Italian validation Lichess 30,375 games (7.1% transpositions, Kish n 18,428), 51.6% [50.9–52.3]; OTB 3,823, 54.3% — reproduces the reference table exactly §31.4
Transposition shares QGD Exchange 70.6% Lichess (932 of 1,320) / 44.1% OTB; London 63.6% / 50.8%; Italian 7.1%; Scotch 5.5%; Najdorf 6.Be3 12.4% §31.4
Query evals (SF19 d20) Italian +0.16, Scotch +0.08, Najdorf 6.Be3 +0.25, QGD Exchange +0.26, London +0.15 §31.4
Najdorf 6.Be3 (Anchor C) 363 balanced Lichess games, Kish n 203, no band with Kish ≥ 100; OTB 471, only 2400+ reaches 100 (126, 52.4%) §31.4
6.Be3 history (master games) 0.7% (1960s) → 35.2% (1990s) → 47.0% (2000s) → 16.3% (2020s); earliest Rossolimo–Fischer, US Ch 1966 §31.4
Weights truth test Bullet share truth 35.90 / unweighted 29.47 / weighted 35.88 / analysed only 20.72; Kish n of subset 542,092 §31.5
Heat maps OTB knights e6 +5.7, d6 +5.6 (0.36% of side-games); f3 33.4%, adj +0.1; Spearman(freq, adj) −0.12 OTB / −0.33 Lichess §31.6
Pawn-up endings (OTB classical 2400+) Wins 41.6 (entry) / 46.0 (settled) / 46.1 (reference); 26.7% of entry positions mid-exchange; median eval +0.40 at 2400+ vs +1.80 at 1400–1599; ≥ +1.50 bucket 72.5% → 84.7% §31.7
Time used by move 15 Slowest quintile adj −7.71 (3+0), −6.87 (5+0), −4.01 (10+0); level positions slow − fast: 3+0 −4.45 (SE 1.08), 10+0 +1.66 (0.97); clock < 10% of base −16.20 to −17.89 §31.8
Split-half 183 cells, 63 significant in A, 42 replicate, r = 0.55 (by player 0.70); Englund 2200–2399 −5.41 → +0.78; 2% subsample: 10 significant, 0 replicate, r = 0.02 §31.9
Replication by size 100%: 66 sig / 42 rep (r 0.33); 20%: 30 / 7; 2%: 9.3 / 0; Bonferroni ( z
Checkpoint (Dev) Italian 3.Bc4 67.9% [56.2–77.6] n = 70 vs database 52.7% [50.5–54.8] → separate; Najdorf 26.3% [11.8–48.8] n = 19 vs database n = 8 (Kish 4) → overlap Project Checkpoint
Fedoseev–Harikrishna, Polanica-Zdrój 2026 After 30.Rxd5: +0.00 (d18) / −0.06 (d24); 30...Re2 31.Rf1 Rxa2; ½–½ §31.7; CS1 Row A; B5
Carlsen–Firouzja, Norway Chess 2026 r11 After 32...Qxf8: +1.68 (d18) / +1.82 (d24), 33.Qe2; 33.Kh1 0.00; clocks 36.8 vs 4.0 min; 39...Qxb4 with 1.8 min left (+2.79 d18 / +3.95 d24); 47.Nxc6+ §31.7; CS1 Row B; B6–B8
Erigaisi–Martirosyan, Bundesliga 2026 Relay eval +5.21 / −6.15 after plies 44–45 vs SF19 d20 −0.31 / −0.43 — a relay glitch CS1 Row C

Threshold concepts and likely misconceptions

Threshold concept: every statistic is a query (filter, grouping, summary), and the definition is the finding. Students who cross it stop asking "what does the database say?" and start asking "which games, which comparison, which definition?" The decision checklist at the end of the chapter is the threshold written as a habit.

Misconceptions to expect:

  • "More games means more truth." Four million games can still be 203 effective games for the question you asked (the English Attack). Cell size matters more than total size.
  • "A raw score measures the opening." Who plays it is part of the score: r = 0.74 between raw and Elo-expected scores across families.
  • "The Sicilian scores 55% for GMs and 48% at 1200." The data says the opposite in both places: 47.2% for Black in the masters explorer, about 50% at club level on Lichess.
  • "Searching the move order is good enough." In set-up systems most games transpose (QGD Exchange 70.6%, London 63.6%).
  • "Weights fix everything." They fix the design (one in eight); they cannot fix self-selection in analysed games.
  • "Masters convert extra pawns worse than club players." Their "pawn-up" endings are objectively closer to level (median +0.40 vs +1.80); within an eval bucket conversion rises with rating.
  • "Low clocks cause losses." The low clock is partly an effect of a losing game. Use pre-outcome predictors.
  • "The top row of my sorted table is my best finding." It is the noisiest — the Englund cell flipped sign in the other half.

How the four tracks use this chapter

  • ♟️ Improver: the hook, 31.3, 31.4 (next-move tables for the openings they play), 31.7 (what "a pawn up" means at their level) and 31.8 (budget the opening at 3+0). Code can be skipped. Exercises A1, A3, A6, B1–B6, D1.
  • 📊 Analyst: everything — filters (31.2), adjustment (31.3), weights (31.5), definitions (31.7), replication (31.9); both case studies. Exercises A1–A9, C1, C3–C6, D2–D4, M5, E1–E3.
  • 🏆 Competitor: 31.4 next-move tables and Exercise D3 (which pool Grace should use for which question); the Carlsen–Firouzja conversion (B6–B8) as a technique drill.
  • 💻 Developer: 31.1, 31.4 and 31.10 plus the Project Checkpoint. load_lichess/load_otb/load_features, summarise (n, Kish n, score, Wilson interval, draw %, expected, adj), split_half, build_prefix_index, query_line, transposition_recall, heatmap. Exercises C2, C5, M3, E2.

Running the code

All scripts run from the chapter directory; saved outputs are in code/out_*.txt, so a class without the data can read every result. Engine work uses one process with two threads and the shared Stockfish 19 cache.

Script What it shows Runtime
ch31_common.py Paths, figure style, board helper that writes the position line —
01_inventory.py Counts, both filter funnels, OTB draw rate by speed, hourly skew ~15 s
02_sample_weights.py Weighted vs unweighted vs analysed-only, graded against the 4M truth ~11 s
03_openings_by_band.py Confounding tables, family × band adj, split-half; writes ch31_family_band.csv ~36 s
04_position_queries.py Prefix index of 864,816 Lichess + OTB games, five queries, recall checks, SF19 d20 ~2.7 min
05_heatmaps.py Knight and bishop maps from the reference CSVs ~7 s
06_endgame_conversion.py Three endgame-start definitions; stored evals by bucket ~70 s
07_time_usage.py 150,000 games, used-by-move-15 quintiles, eval-controlled comparison ~2.4 min
08_exercise_positions.py SF19 MultiPV 3 at d20 plus d24 for the exercise boards cached
09_history_query.py Master-games prefix index; 6.Be3 and QGD Exchange by decade ~60 s
case_study_01.py, case_study_02.py Three rows (SF19 d18/d24, d16 game analysis); replication vs database size ~42 s for CS2
project_checkpoint.py Dev's position-based comparison; split-half on the Italian by band ~38 s

Expect 19 board images and 16 charts (7 boards and 14 charts are embedded in the chapter text).

Lab plan: the query engine (35 minutes)

  1. Build the index (5 min). Run database.build_prefix_index("lichess") (about 77 s) and the OTB version (about 14 s) while you explain row-group streaming. Point out that the 446 MB move-text column is never in memory at once.
  2. Validate first (5 min). Query the Italian ("e4 e5 Nf3 Nc6 Bc4") and check the output against the reference row: 30,375 games, Kish n 18,428, 51.6%; OTB 3,823, 54.3%. Make this a rule: no new query until the known one reproduces.
  3. Transpositions (10 min). Pairs query the QGD Exchange with transpositions=False, then True. They should see the exact-only count collapse to 388 of 1,320. Ask them to find two move orders in the transposition list (for example 1.d4 Nf6 2.c4 e6 3.Nc3 d5).
  4. Recall check (5 min). Run transposition_recall on one query. Discuss why "100% on a sample with 19–819 true matches" means "no misses found", not proof — the bag-of-moves pre-filter cannot see a knight that reached f3 via d2.
  5. Own opening (10 min). Each pair runs the chapter's final Try it on an opening they play: query, next-move table with intervals, then SF19 d20 on the worst-scoring common reply. Each pair reports one sentence for the database and one for the engine.

Troubleshooting: if a student's bot filter collapses the row count, they have written != "BOT" — switch to chessdata.is_bot_game(df). Any Lichess population number must pass weight="sample_weight". chessdata.lichess_moves with a long id list is slow; database.load_movetext is the fast path.

In-class demos

Board demo

Set up the Scotch after 4.Nxd4: r1bqkbnr/pppp1ppp/2n5/8/3NP3/8/PPP2PPP/RNBQKB1R b KQkq - 0 4. Ask: "Black to move. What do 1500-rated players play most often here?" Reveal 4...Nxd4 (43.0% of Lichess replies) and play 5.Qxd4 on the board. Ask the class why the engine likes White by +0.76 (d20): Black has traded his only developed piece, White's queen is centralised with no tempo lost, and ...Nc6 can no longer hit it. Then reveal that over the board 4...Nxd4 is 3.5% of replies, and that after 4...Nf6 the engine gives +0.10. The Scotch's "best opening" score rests partly on one popular inaccuracy.

Follow-up if time allows: Fedoseev–Harikrishna after 30.Rxd5 (8/p4pk1/5rp1/3R3p/4r3/1P4P1/P4PKP/2R5 b - - 0 30). "White is a pawn up by every database definition. Black to move." Students who find 30...Re2 (−0.06 at d24, with 31.Rf1 Rxa2) have understood why "one pawn up" is a filter, not a description.

Data demo

Project the split-half table from 31.9. First ask the class to predict: "With 2.6 million games, how many 'significant' opening × band cells will hold up in the other half? And with 52,000 games — more than most players will ever look at?" Then reveal 42 of 63, and 0 of 10 (r = 0.02). Finish with Case Study 2's 1600–1799 column: the Italian looks like +4.65 in the 2% sample and is −0.18 in the full data. Ask: "How many games are in your own opening file?"

Exercise guidance

  • Part A: everyone. A2 (the bot filter) and A8 (reverse causality) are the ones students most often get half-right. A5 should mention that Kish n goes inside the Wilson interval.
  • Part B:
  • B1: students find 4...Nf6 but cannot say why 4...Nxd4 is worse; insist on the explanation (development traded, queen centralised for free).
  • B2: the trap is ranking by the second decimal. 3...Bc5 and 3...Nf6 are both +0.23 (MultiPV d20), and the database intervals after all three replies overlap.
  • B5: 30...Re2! is the point of the chapter's 31.7 in one move.
  • B6: many pick 33.Kh1 "for safety"; the engine's 0.00 after 33...Qf2 shows the opposite. The extra pawn is only worth something while the king is safe.
  • B8: several moves win (47.Qh7+ scores higher at d24); credit students who justify 47.Nxc6+ as the practical choice against an opponent short of time.
  • Part C: C1 and C4 are accessible; C2, C3, C5 and C6 are full lab exercises (each reuses a chapter script). C4 compares with the reference 81.8% (two pawns up, overall) and 78.5% at 2400+.
  • Part D: D1 (switch to the Sicilian at 1200 vs 2000?) and D3 (which pool for Grace?) make good short essays; D4 asks for an honest two-sentence verdict on Dev's Italian.
  • Part M: M5 (does the Elo formula's over-prediction bias the adjustment?) is the best bridge to Chapter 30.
  • Part E: E1 (a full month, split by week) is a strong term project.

Assessment ideas

  1. Audit a claim. Give a sentence such as "Opening X scores 56% — the best in the database". Students write the six questions of the decision checklist and say which numbers they would need before accepting it.
  2. Filter memo. Students run one filter cascade (C1) and write 150 words on which filter changed the answer most and why.
  3. Position-query report. For one opening, students produce the next-move table with intervals, the transposition share and one SF19 evaluation at a stated depth, plus two sentences: what the database says, what the engine says about why.
  4. Quiz. The chapter quiz (22 questions, 28 points; 24+ means "move on") fits a 30-minute slot.
  5. Developer milestone. query_line reproduces the Italian row; summarise returns Kish n; split_half runs on one family × band table.