Skip to content

V68: counterfactuals, what would have to change - #168

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

F7, the last feature proposed. For a row typed in the what-if panel the lab said what the model predicts, what weighed (Shapley) and what happened (the glass box). A new What would have to change? button answers the fourth question: the smallest change that makes the inspected model answer another class.

A search a reader can follow, not an optimisation:

  1. one column at a time: every value the training rows hold is tried in place of the row's own, and the column keeps the nearest one that flips the answer;
  2. two columns together, only when no single column flips it;
  3. never three.

Only observed values, nothing interpolated; free text is never edited; the columns the user ticks as locked are left alone (the lab does not guess that an age cannot change). With three classes or more, one class can be asked for. Nothing found is an answer, given with what was tried. Each change has a button to load it into the form.

  • train/counterfactual.ts (pure): observedValues, searchCounterfactuals, and counterfactualsFor, the worker entry.
  • Worker request counterfactual, response counterfactual-result (run-derived, cleared with each new row, saved nowhere).
  • components/insights/CounterfactualView.tsx, rendered inside WhatIfPanel; a lock checkbox beside each field.

Measured before the panel

Four classification demos, three seeds, 60 test rows each, seven families.

Demo One column is enough Two are needed Nothing found
titanic 63 to 98 % 2 to 30 % 0 to 9 %
fraud 28 to 100 % 0 to 69 % 0 to 9 %
iris 96 to 100 % 0 to 4 % none
reviews 0 to 100 % 0 to 38 % 0 to 100 %

On reviews most families find nothing: the answer is in the text. Two findings changed the design:

  • Plausibility. 8 to 60 % of the nearest changes landed farther from every training row than 95 % of training rows are from their nearest neighbour. The search now keeps, per column, the nearest flipping value that stays inside that cloud, and flags the rest. On iris about half stay flagged: its four columns move together.
  • Fragility. Of the other trained models that agreed on the row, only 14 to 54 % answered the new class for the same change. Each answer says how many follow.

Known limit, stated on the panel

The lab does not know that two columns say the same thing. On titanic the forest proposed adult_male: True to False while sex stayed male: each value exists, the row does not, and the far flag does not catch it. The panel and the limits page tell the user to lock or drop the duplicate.

Not in this wave

Advice about the world (a counterfactual speaks of the model); more than two columns; editing free text; regression; a re-imported model; the chosen decision threshold; a published method such as DiCE.

Docs

New how-to page « find what would change a prediction » in both languages, limits, ML reference, link from « replay a prediction », README (new row, and the stale sentence listing proposals), PLAN row V68, changelog, version 1.68.0. The list of proposed features in PLAN.md is now empty.

Checks

  • Lint, typecheck (apart from the xlsx types unreachable in my sandbox), format: clean.
  • Unit: 1315 passed locally, 5 failed, all in spreadsheet.test.ts (the xlsx tarball cannot be fetched in my sandbox; CI is the reference). 26 new tests; every counterfactual returned is replayed through predict.
  • E2E: 133 passed locally after a fresh build, 1 failed (lab.spec.ts:31, the Excel upload, same cause). New e2e/counterfactual.spec.ts loads a change into the form and checks the prediction shown moves, then locks that column.
  • The full e2e run caught two defects of this wave before the push: the lock checkbox sat inside its field's label (two existing tests that fill a field by its label failed), and the new page quoted a duration, which a docs test refuses. Both fixed.
  • Screenshot review in French, light desktop and dark mobile, no sideways overflow.

Generated by Claude Code

For one row of a classification, the what-if panel can now look for the
smallest change that makes the inspected model answer another class:
one column at a time, then two, never three. Only values the training
rows hold are tried, free text is never edited, and the columns the
user locks are left alone. Nothing found is an answer, given with what
was tried.

Measured first on the classification demos. One column is enough on
most rows of three demos and two are needed on up to 69 %. Two findings
shaped the panel: 8 to 60 % of the nearest changes were farther from
every training row than training rows are from each other, so the
search prefers a change that is not and flags the rest; and only 14 to
54 % of the other trained models followed the same change, so each
answer says how many do.

New how-to page in both languages, limits, reference, README, PLAN row
V68, version 1.68.0. The list of proposed features is now empty.

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 19:59
@dapiced
dapiced merged commit b99f750 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