SpectoPrep documentation#
SpectoPrep finds effective spectroscopic preprocessing pipelines with Bayesian optimization. It searches over scatter correction, smoothing, baseline, scaling and related transforms, then fits a ridge model whose penalty is selected by cross-validation.
from spectoprep import PipelineOptimizer
import numpy as np
rng = np.random.default_rng(0)
X = rng.normal(size=(80, 200))
y = rng.normal(size=80)
groups = np.arange(80)
optimizer = PipelineOptimizer(
X_train=X,
y_train=y,
groups=groups,
preprocessing_steps=["msc", "savgol", "snv", "scaler"],
cv_method="group_kfold",
n_splits=5,
max_pipeline_length=2,
allowed_preprocess_combinations=[1, 2],
)
best_params, best_pipeline = optimizer.bayesian_optimize(init_points=5, n_iter=20)
Why SpectoPrep?#
Joint search — pipeline structure and transform hyperparameters in one Bayesian loop.
Group-aware CV —
group_kfold,group_shuffle_split, orleave_p_group_outso replicate spectra stay together.Modern ridge backend — downstream
OptimizedRidgeCVselectsalphaby CV (no manualridge_alphasearch).Production tooling — structured logging (
structlog), a Typer CLI, and a full test suite.
Scope#
SpectoPrep targets regression chemometric workflows (NIR, MIR, Raman and similar). Classification is not supported.
User guide
- Installation
- Usage
- Getting started
- Corn NIR benchmark (Cargill / Eigenvector)
- 1. Load data
- 2. Raw spectra (full set, inverted wavelength axis)
- 3. Load tracked optimal preprocessing (from full benchmark)
- 4. Short live demo on one constituent (Protein)
- 5. Preprocessing comparison — full spectra, inverted x-axis
- 6. Predicted vs reference + optimisation diagnostics
- 7. Paper figures (nested-CV, all constituents)
- Tutorial (legacy milk example)
Reference
Project