Skip to content

V66: the glass box, one row replayed through the model - #166

Merged
dapiced merged 1 commit into
mainfrom
dom/modest-darwin-4oe9q0
Nov 13, 2026
Merged

dapiced merged 1 commit into
mainfrom
dom/modest-darwin-4oe9q0

Conversation

@dapiced

@dapiced dapiced commented Nov 13, 2026

Copy link
Copy Markdown
Owner

What

The third and last part of F8. For a row typed in the what-if panel the lab gave a prediction and a Shapley explanation: what weighed. A new Replay it step by step button tells what happened, for four families:

Family What the replay shows
Decision tree each question asked of the row, in the units of the file, how many training rows were asked the same, and the leaf it ends in
Random forest how many of its 40 trees answered each class, or the spread of their values
k-NN the 5 rows of the file the row was compared to, with distance, target and main columns; ties flagged
Gradient boosting the prediction round after round, up to three rounds told in full, and the error on the validation rows as rounds add up

Other families say why there is nothing to replay.

  • train/glass-box.ts (pure): replayTree, replayForest, replayNeighbours, replayBoosting, stagedValidation, describeSplit, and replayRow, the worker entry.
  • gbdt.ts exports binValue and its node type; trainKnn gains a neighbours member off the hot path; TrainArtifacts.fitIndices names the rows a capped family was fitted on. No training figure changes.
  • Worker request replay, response replay-result (run-derived, cleared with each new what-if row, saved nowhere).
  • components/insights/GlassBoxView.tsx, rendered inside WhatIfPanel.

Measured before building

One rule: the replay is the model, so its last step must equal predict. Six demos, five seeds, 2,560 test rows:

  • zero mismatch for the tree, the k-NN and the boosting, in binary, multiclass and regression;
  • the forest missed 3 rows of titanic: on a 20 to 20 vote the library keeps the first class to reach the top count, in the order of its trees. The replay now does the same and flags a tied vote;
  • every question of the tree translates into the units of the file on five demos, and 6 of 1,878 on reviews (free text: a question is the weight of a word, shown as the model sees it);
  • k-NN: the next row is exactly as far as the last neighbour kept on 17 % of titanic's test rows and 39 % of energy's;
  • boosting: the validation error was lowest well before round 120 (more than 2 % under the final error) on 17 runs of 30, and on energy it never beat its starting point on three seeds of five.

That last finding is shown in the panel, on validation rows and never on the test set, and sets nothing. Early stopping is proposed as F9 in PLAN.md, to be measured on its own.

Not in this wave

Replaying how a model was trained; a network, a linear model, a blend, or a forest tree by tree; stopping the boosting early; a re-imported model; drawing a whole tree.

Docs

New how-to page « replay a prediction » in both languages, limits, ML reference, link from « read a learning curve », README, PLAN row V66 (F8 removed as complete, F9 added), changelog, version 1.66.0.

Checks

  • Lint, typecheck (apart from the xlsx types unreachable in my sandbox), format: clean.
  • Unit: 1289 passed locally, 5 failed, all in spreadsheet.test.ts (the xlsx tarball cannot be fetched in my sandbox; CI is the reference). 43 new tests, among them the invariant on every test row for each family and task.
  • E2E: 132 passed locally after a fresh build, 1 failed (lab.spec.ts:31, the Excel upload, same cause). New e2e/glass-box.spec.ts replays a row through each family and checks the last step against the what-if prediction.
  • Screenshot review in French, light desktop and dark mobile, no sideways overflow. It caught the boosting telling rounds 1, 2 and 3, the same tree three times: the rounds told now ask different questions.

Generated by Claude Code

Beside the Shapley explanation (what weighed), the what-if panel can now
replay its row through the inspected model: the questions a decision
tree asked and the training rows that share its leaf, the count of a
forest's trees, the five rows of the file a k-NN compared it to, the
prediction a boosting builds round after round with its error on the
validation rows.

The replay walks the model itself. Measured first on 2,560 test rows of
the six demos: its last step equals predict on every row for the tree,
the k-NN and the boosting; the forest missed three rows of titanic until
its tie rule was copied. Questions are written in the units of the file.

The measure also showed that the boosting's validation error is lowest
well before its last round on 17 runs of 30. It is shown and sets
nothing; early stopping is proposed as F9.

New how-to page in both languages, limits, reference, README, PLAN row
V66, version 1.66.0. F8 is complete.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AyBsUet8WybTG986ubroar
@dapiced
dapiced marked this pull request as ready for review November 13, 2026 18:50
@dapiced
dapiced merged commit a94e2a6 into main Nov 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants