Skip to content

Fix train/test leakage, stale model on edit, and ignored batch size - #1

Merged
rxslice merged 1 commit into
mainfrom
fix/ml-correctness
Nov 14, 2026
Merged

rxslice merged 1 commit into
mainfrom
fix/ml-correctness

Conversation

@rxslice

@rxslice rxslice commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Fixes audit findings ML-1 to ML-3, and removes the AI Studio template leftovers.

Correctness

  • ML-1 (data leakage): the z-score means and standard deviations, for both features and the regression target, were computed over all rows before the split, so test rows shaped the scaler. The split now happens first, and the scalers are fitted on training rows only.
  • ML-2 (stale model): the rebuild effect depended on rows.length, so editing a cell kept training the old model on the old data. It now depends on rows.
  • ML-3 (batch size ignored): batchSize was read and then never used; every sample got its own update. NeuralNetwork.trainBatch() now averages gradients over each batch and applies one momentum update. backprop() is kept as a batch-of-one wrapper.

Cleanup

  • Removed unused @google/genai, express, dotenv, motion, tsx and @types/express, plus .env.example (no API key is needed).
  • Renamed the package from react-example to forge-spreadsheet-ml.
  • Replaced the AI Studio README.
  • Added package-lock.json and a CI workflow (type check, tests, build).

Verification

  • tests/math.test.ts: 3 of its 4 tests fail on the old code and all 4 pass now.
  • dev/check-cell-edit-resets.cjs is a Playwright check: train 3 epochs, then edit a cell. On the old code the epoch stays at 3; now it resets to 0. No page errors.
  • tsc --noEmit and vite build both pass.

No licence is added; that choice is the owner's.


Generated by Claude Code

- ML-1: fit feature and target scalers on the training split only
- ML-2: rebuild the model when any cell changes, not only the row count
- ML-3: honour the batch-size setting with averaged mini-batch updates
- Remove unused Gemini, express, dotenv and motion dependencies
- Rename the package, rewrite the README, add a lockfile, vitest and CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011GFY8v4QeVYzawpSLcJCzz
@rxslice
rxslice merged commit 7bea651 into main Nov 14, 2026
1 check 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