Skip to content

Batch phase 3: sklearn transformer facades and f_rupture - #461

Open
kgdunn wants to merge 1 commit into
claude/batch-phase2-online-monitoringfrom
claude/batch-phase3-transformers
Open

Batch phase 3: sklearn transformer facades and f_rupture#461
kgdunn wants to merge 1 commit into
claude/batch-phase2-online-monitoringfrom
claude/batch-phase3-transformers

Conversation

@kgdunn

@kgdunn kgdunn commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds sklearn BaseEstimator / TransformerMixin facades over the existing batch free functions, so a batch workflow can be expressed as a pipeline and the learned state is carried on the fitted estimator: BatchScaler (range scaling with inverse_transform), ResampleAligner (linear resampling to a common length), DTWAligner (iterative weighted DTW that learns a reference and weights and aligns new batches to them), and BatchFeatureExtractor (a batch dict to a batch-by-feature matrix suitable as the X block of a PLS-to-quality model). The free functions are unchanged and remain the implementation layer.
  • Implements the previously-stubbed f_rupture via the optional ruptures library (PELT changepoint detection), and re-points the batch extra to ruptures - it previously declared openpyxl and scikit-image, which were imported nowhere.

This is Phase 3 of the batch modernization plan (pipeline ergonomics + feature completion).

Note on base branch: stacked on claude/batch-phase2-online-monitoring (#460), which is stacked on Phase 1 (#459). GitHub will retarget the base automatically as each parent merges. Review #459, then #460, then this.

Test plan

  • tests/batch/test_transformers.py: scaler round-trip; resampler equal-length + auto-reference; DTW aligns the training set and a held-out batch to the reference length; feature matrix shape/index and feeding a PLS model; unknown-feature guard; f_rupture detects an injected step (guarded by importorskip("ruptures")) and rejects multi-column input
  • Full batch suite: 121 passed; ruff check . and mypy src/process_improve clean

Checklist

  • Version bumped in pyproject.toml (MINOR: 1.56.0 -> 1.57.0) and CITATION.cff synced
  • Tests added or updated where relevant
  • ruff check . passes
  • CHANGELOG.md updated

🤖 Generated with Claude Code

https://claude.ai/code/session_01SyEpexCyqHn1rwTMYQSiP6


Generated by Claude Code

Adds BaseEstimator/TransformerMixin facades over the existing batch
free functions so a batch workflow can be an sklearn pipeline, with the
learned state carried on the fitted estimator: BatchScaler (range
scaling with inverse_transform), ResampleAligner (linear resampling to
a common length), DTWAligner (iterative weighted DTW, learning a
reference and weights and aligning new batches to them), and
BatchFeatureExtractor (batch dict to a batch-by-feature matrix for
PLS-to-quality). The free functions are unchanged and remain the
implementation layer.

Implements the previously-stubbed f_rupture via the optional ruptures
library (PELT changepoint detection), and re-points the batch extra to
ruptures - it previously declared openpyxl and scikit-image, which were
imported nowhere.

Bumps to 1.57.0 with CITATION, CHANGELOG, and docs updates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyEpexCyqHn1rwTMYQSiP6
kgdunn pushed a commit that referenced this pull request Aug 21, 2026
…plots, loaders

Consolidates the stale #459 / #460 / #462 stack onto current main, as
one commit series inside the mid-course-correction PR:

- BatchPCA: batchwise-unfolded (Nomikos-MacGregor) PCA with an optional
  initial-conditions (Z) join, composed over multivariate.PCA and
  MCUVScaler; batch-level scores, SPE, T2, contributions and the plot
  and limit conveniences.
- BatchPCA.predict_online: projection to the model plane for a
  partially-observed batch (upgraded to the shared missing-data
  projection API in a later commit series).
- BatchMonitor: time-varying online SPE and T2 limits learned from good
  batches, with per-sample alarms, plus online_monitoring_plot.
- BatchPLS: batchwise-unfolded [Z | X] -> Y regression to final
  quality. Refreshed beyond the original: the class now owns both
  scalers publicly (center_/scale_ for the unfolded block,
  y_center_/y_scale_ for the quality block; the inner PLS runs with
  scale=False), reports beta and RMSE in engineering units, and adds a
  prediction_interval wrapper. The mid-course corrector reads these
  public attributes instead of any PLS internals.
- time_varying_loading_plot and contribution_at_time_plot for the
  unfolded structure; dataset loaders load_nylon, load_dryer and
  load_batch_fake_data for the bundled batch CSVs.
- Integration test: BatchPLS on a simulator historical campaign (80
  batches, 4 components) reaches fit R2 0.83 and out-of-sample
  correlation 0.80 against fresh batches; thresholds pinned below with
  margin.

The #461 transformer facades are deliberately not re-landed; they can
be revived separately if wanted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZAyiPT8xURSdi24yFKCra
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