Skip to main content

SpectoPrep

PyPI version CI status Coverage Conda version Documentation Status

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

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}
}

Metadata

Release files for spectoprep 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spectoprep 1.0.5
File Size Uploaded Provenance Actions
spectoprep-1.0.5.tar.gz 222.1 kB With provenance Details for spectoprep-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spectoprep 1.0.5
File Interpreter ABI Platform Actions
spectoprep-1.0.5-py3-none-any.whl Python 3 none any Details for spectoprep-1.0.5-py3-none-any.whl

Total release size: 259.8 kB

Release files / spectoprep-1.0.5.tar.gz

Download URL spectoprep-1.0.5.tar.gz
Size 222.1 kB
Tags Source
SHA-256 checksum
How to use checksums
535c4d78adc032ed438062a566079965a2c45a3a8e15b3f33e679376d0880713
BLAKE2b-256 checksum
How to use checksums
a89344ef044a6f598d56ce2023d5a7b2a0b4a56d681315a1b570b68217c4b2e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / spectoprep-1.0.5-py3-none-any.whl

Download URL spectoprep-1.0.5-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
916109d146f5a7cbc1025731288f64b67292f0b3691ad3db9f983127c3134dfe
BLAKE2b-256 checksum
How to use checksums
e79c124fb5a58f55fd8c883b68639299de9c08d4a8b2e96118e3ce7aa68cac5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for spectoprep 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spectoprep-1.0.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page