Bayesian optimization of spectroscopic preprocessing pipelines for chemometric regression (NIR, MIR, Raman, and related modalities).
Overview
SpectoPrep searches over combinations of scatter correction, smoothing, baseline correction, scaling and related transforms. Each candidate pipeline is scored with group-aware cross-validation and fitted with OptimizedRidgeCV, which selects the ridge penalty by CV. The goal is a reproducible, leakage-aware alternative to hand-tuned preprocessing recipes.
Features
Bayesian pipeline search over structure and transform hyperparameters
Group-aware CV: group_kfold, group_shuffle_split, leave_p_group_out
RidgeCV downstream model (no manual ridge_alpha in the search space)
Broad preprocessing catalogue (MSC, EMSC, SNV, Savitzky–Golay, ALS, scalers, PCA, …)
Structured logging via structlog and a Typer CLI (spectoprep info)
Visualization helpers for spectra and optimization summaries
Installation
pip install spectoprep
Or:
conda install -c habeebest spectoprep
PyPI and the habeebest conda channel are both published automatically from tagged releases (see updated_package_deployment.md).
Requires Python 3.10+.
Quick start
import numpy as np
from spectoprep import PipelineOptimizer
rng = np.random.default_rng(0)
X_train = rng.normal(size=(80, 200))
y_train = rng.normal(size=80)
groups = np.arange(80)
optimizer = PipelineOptimizer(
X_train=X_train,
y_train=y_train,
groups=groups,
preprocessing_steps=["msc", "savgol", "detrend", "scaler", "snv"],
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=25,
n_iter=200,
)
summary = optimizer.summarize_optimization()
predictions, rmse, r2 = optimizer.get_best_pipeline_predictions(best_pipeline)
CLI
spectoprep version
spectoprep info
Selected preprocessing methods
msc / emsc: multiplicative (extended) scatter correction
snv / lsnv / rnv: (localized / robust) standard normal variate
savgol: Savitzky–Golay filtering / derivatives
detrend / als: linear detrend / asymmetric least squares baseline
scaler / robust_scaler / meancn: column scaling and mean centering
pca / select_k_best: dimensionality reduction and feature selection
Run spectoprep info for the full catalogue.
Documentation
Read the Docs: https://spectoprep.readthedocs.io
GitHub Pages: https://habeeb3579.github.io/Spectoprep/
Limitations
SpectoPrep currently supports regression only. Classification pipelines are out of scope.
Contributing
Contributions are welcome. See CONTRIBUTING.rst and open a pull request.
License
MIT — see LICENSE.
Citation
If you use SpectoPrep in research, please cite:
@article{babatunde2025automated,
title={Automated Spectral Preprocessing via Bayesian Optimization for Chemometric Analysis of Milk Constituents},
author={Babatunde, Habeeb Abolaji and McDougal, Owen M and Andersen, Timothy},
journal={Foods},
volume={14},
number={17},
pages={2996},
year={2025},
publisher={MDPI}
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spectoprep-1.0.2.tar.gz.
File metadata
- Download URL: spectoprep-1.0.2.tar.gz
- Upload date:
- Size: 217.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f71cb57c948ae6c1f66933b7ba5ff7f3ff9a0b879e21c36e621a5b400dad4258
|
|
| MD5 |
2a993ba3d5137c862d58e2faa131877c
|
|
| BLAKE2b-256 |
c1dc31375a9adbb1c02c8d1bd9bc41ff9f46d5922fa4b7dfee13cb46f0293a2e
|
Provenance
The following attestation bundles were made for spectoprep-1.0.2.tar.gz:
Publisher:
release.yml on habeeb3579/Spectoprep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spectoprep-1.0.2.tar.gz -
Subject digest:
f71cb57c948ae6c1f66933b7ba5ff7f3ff9a0b879e21c36e621a5b400dad4258 - Sigstore transparency entry: 2160933084
- Sigstore integration time:
-
Permalink:
habeeb3579/Spectoprep@cc5b10319bee74fba6e14fc27b22d69bdfbaf538 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/habeeb3579
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cc5b10319bee74fba6e14fc27b22d69bdfbaf538 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spectoprep-1.0.2-py3-none-any.whl.
File metadata
- Download URL: spectoprep-1.0.2-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fdefb9d6c584496455a969cce8ee05c0a83e809c63a1dcde88030016adf1472
|
|
| MD5 |
657e5e1e12ef4a40027a270d6090cfc1
|
|
| BLAKE2b-256 |
aa6528d1f61ebf1acd59d68a0ca7a0736b33993278f36193b99de37ced90b6c2
|
Provenance
The following attestation bundles were made for spectoprep-1.0.2-py3-none-any.whl:
Publisher:
release.yml on habeeb3579/Spectoprep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spectoprep-1.0.2-py3-none-any.whl -
Subject digest:
6fdefb9d6c584496455a969cce8ee05c0a83e809c63a1dcde88030016adf1472 - Sigstore transparency entry: 2160933117
- Sigstore integration time:
-
Permalink:
habeeb3579/Spectoprep@cc5b10319bee74fba6e14fc27b22d69bdfbaf538 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/habeeb3579
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cc5b10319bee74fba6e14fc27b22d69bdfbaf538 -
Trigger Event:
workflow_dispatch
-
Statement type: