Legacy — Python documentation
This section preserves the previous Python documentation and its detailed references. Start with the common user and developer guide for the current task-oriented documentation. The Python SDK remains supported; this section keeps its existing guides available.
NIRS4ALL is a comprehensive machine learning library specifically designed for Near-Infrared Spectroscopy (NIRS) data analysis. It bridges the gap between spectroscopic data and machine learning by providing a unified framework for data loading, preprocessing, model training, and evaluation.
Start with the common user and developer guide: choose your language, define data, evaluate candidates, save the refit model and predict. Use the detailed references when you need exact parameters.
Task-oriented chapters for Python, R, JS/WASM, MATLAB/Octave, Rust and CLI.
Pipelines, datasets, branching, generators, cross-validation, augmentation, and deployment.
Step-by-step how-to guides for preprocessing, stacking, export, and more.
Complete API reference, pipeline syntax, and operator catalog by category.
Architecture, internals, the controller pattern, and contribution guidelines.
Candidate architecture, workspace conversion, API/ABI/schema identities, support window, examples, and FAQ.
Documentation
- Getting Started
- Concepts
- User Guide
- Data Handling
- Loading Data
- Synthetic Data Generation
- Signal Types and Conversion
- Sample Repetition & Aggregation
- Heterogeneous Source Repetitions
- Tutorial: Heterogeneous Source Repetitions
- Raw multimodal pipelines
- Fusion tardive avec observations partielles
- Native multimodal early fusion
- Octave models in a Python multimodal workflow
- Sample Filtering User Guide
- Overview
- Coming Soon
- See Also
- Preprocessing
- Data Augmentation
- Pipelines
- Models
- Model Training
- Hyperparameter Tuning
- Search source subsets, preprocessing chains and Ridge versus PLS
- Native tuning and conformal calibration
- Native PLS phase controls
- Native PLS HPO within each outer fold
- Initialize SGD REFIT from an explicit CV fold
- AOM Models
- Deep Learning Models
- TabPFN for NIRS — fixed recipe (no HPO)
- Overview
- Supported Model Frameworks
- Quick Example
- Built-in NIRS Models
- See Also
- Predictions
- Deployment
- Visualization
- Extended Python API
- Troubleshooting
- Logging System User Guide
- Understanding Scores, Evaluation, and Refit
- Overview
- Additional Topics
- See Also
- Data Handling
- Reference
- Writing a Pipeline in nirs4all
- Pipeline Keywords Reference
- Operator catalog: choose a job, then inspect the method
- Choose a pipeline node by what you want to do
- Transforms Reference
- Choose a transform by the effect you want to remove
- Same worked recipe in JSON, YAML and Python
- Scatter Correction and Normalization
- Smoothing
- Derivatives
- Baseline Correction
- Orthogonalization
- Signal Conversion
- Wavelet Transforms and Feature Extraction
- Feature Selection
- Resampling and Cropping
- Target Transforms
- See Also
- How to interpret and combine the families
- A complete, small transformation experiment
- Learning exercises and exact APIs
- Ragged temporal encoding: SequenceSummary
- Fixed convolution features: FCKStaticTransformer
- Augmentation Operators Reference
- Choose a perturbation that resembles real acquisition variability
- Same worked recipe in JSON, YAML and Python
- Noise
- Baseline Drift
- Wavelength Distortion
- Spectral Distortion
- Mixup
- Physical / Instrumental
- Environmental
- Scattering
- Edge Artifacts
- Spline-Based
- Random Geometric
- See Also
- What the perturbations mean
- Sample versus feature augmentation
- Diagnose an augmentation experiment
- Built-in Models Reference
- Choose a model by the target and structure of your data
- Same worked recipe in JSON, YAML and Python
- Adaptive PLS (Auto-Preprocessing)
- AOM-Ridge and FastAOM
- Standard PLS
- Orthogonal PLS
- Multi-Block and Domain-Invariant
- Sparse and Interval
- Kernel PLS
- Locally Weighted
- Nonlinear PLS
- Meta-Model Stacking
- AOM-PLS Operator Bank
- See Also
- Understand the fitted object
- Interpret a component sweep
- More models than this spectroscopy shortlist
- Typed multimodal estimators
- Principal component regression
- Splitters Reference
- Filters Reference
- Choose a criterion, then decide what its flag means
- Same worked recipe in JSON, YAML and Python
- YOutlierFilter
- XOutlierFilter
- SpectralQualityFilter
- HighLeverageFilter
- MetadataFilter
- CompositeFilter
- Tag vs Exclude Keywords
- See Also
- Read a flag as evidence, not a diagnosis
- Where filtering belongs in a workflow
- Generator keywords: choices, combinations and their exact outputs
- Clickable keyword index
- Alternatives and numeric values
- Products, paired parameters and ordered alternatives
- Sets and sequences: why order changes the count
- Search size and reproducibility
- Constraints: remove choices you do not want to test
- Reuse a search specification
- Advanced names with limited effects
- Inspect before fitting
- Combination Generator Documentation
- Configuration Reference
- Configuration Reference
- Metrics Reference
- Predictions API Reference
- Session API Reference
- Public Interfaces and Runtime
- Public execution matrix
- Native Capability Preflight
- Native conformal finetuning release audit
- CLI reference
- Workspace Architecture
- Storage API Reference
- Pipeline & Syntax
- Operators by Category
- Results & Deployment
- API Documentation
- See Also
- Developer Guide
- Architecture Overview
- Audit de récupération R2 — backend natif
- Pipeline Architecture Overview
- Native source stacking with upstream preprocessing
- Controller System
- Controllers Introduction
- Controller Philosophy
- Why Not Just Execute Directly?
- Controller Registration Model
- Controller Base Contract
- Controller Families
- Controller Family Map
- Controller Interaction Patterns
- Controller Priority Strategy
- Controller Extension Pattern
- Controller Extension Examples
- Extension Quality Guidelines
- Advanced Topics
- Next Steps
- Caching and Memory Optimization
- Artifacts & Storage
- Artifacts Developer Guide
- Metadata Usage Guide
- Outputs vs Artifacts: Serialization Architecture
- Synthetic Data Generator
- Architecture Overview
- Physical Model
- Core Components
- Extending the Generator
- Wavenumber Utilities (Phase 1)
- Procedural Component Generator (Phase 1)
- Application Domains (Phase 1)
- Extended Component Library (Phase 1)
- Instrument Simulation (Phase 2)
- Environmental Effects (Phase 3)
- Scattering Effects (Phase 3)
- Metadata System
- Classification Generation
- Non-Linear Target Complexity
- Multi-Source Generation
- Exporter System
- Real Data Fitting
- Validation System
- Integration with Test Fixtures
- Performance Considerations
- Predefined Spectral Components
- References
- See Also
- Testing Guide
- Documentation Style: Writing Pipelines
- Explicit DuckDB workspace conversion
- Storage Migration Guide – Webapp Developers
- Overview
- Additional Developer Topics
- Quick Start: Custom Controller
- See Also
- Interactive Example Browser
- API Reference
- Native V1 migration and compatibility guide
Quick Start
import nirs4all
from sklearn.preprocessing import MinMaxScaler
from sklearn.cross_decomposition import PLSRegression
from sklearn.model_selection import ShuffleSplit
# Define and run a pipeline in one step
result = nirs4all.run(
pipeline=[
MinMaxScaler(),
ShuffleSplit(n_splits=3),
{"model": PLSRegression(n_components=10)}
],
dataset="path/to/data",
verbose=1
)
print(f"Best RMSE: {result.best_rmse:.4f}")
result.export("exports/best_model.n4a")
Try Without Data
No dataset? Generate synthetic NIRS spectra to get started:
import nirs4all
# Generate realistic synthetic NIRS data
dataset = nirs4all.generate.regression(
n_samples=500,
components=["water", "protein", "lipid"],
complexity="realistic",
random_state=42
)
# Run a pipeline on synthetic data
result = nirs4all.run(
pipeline=[MinMaxScaler(), {"model": PLSRegression(10)}],
dataset=dataset
)
print(f"RMSE: {result.best_rmse:.4f}")
Tip
See Interactive Example Browser for 50+ working examples organized by topic.
What is Near-Infrared Spectroscopy (NIRS)?
Near-Infrared Spectroscopy (NIRS) is a rapid and non-destructive analytical technique that uses the near-infrared region of the electromagnetic spectrum (approximately 700-2500 nm). NIRS measures how near-infrared light interacts with the molecular bonds in materials, particularly C-H, N-H, and O-H bonds, providing information about the chemical composition of samples.
Key advantages of NIRS:
Non-destructive analysis
Minimal sample preparation
Rapid results (seconds to minutes)
Potential for on-line/in-line implementation
Simultaneous measurement of multiple parameters
Common applications:
Agriculture: soil analysis, crop quality assessment
Food industry: quality control, authenticity verification
Pharmaceutical: raw material verification, process monitoring
Medical: tissue monitoring, brain imaging
Environmental: pollutant detection, water quality monitoring
Features
NIRS4ALL offers a wide range of functionalities:
Spectrum Preprocessing:
Baseline correction
Standard normal variate (SNV)
Robust normal variate
Savitzky-Golay filtering
Normalization
Detrending
Multiplicative scatter correction
Derivative computation
Gaussian filtering
Haar wavelet transformation
And more…
Data Splitting Methods:
Kennard Stone
SPXY
Random sampling
Stratified sampling
K-means
And more…
Model Integration:
Scikit-learn models
TensorFlow/Keras models
Pre-configured neural networks dedicated to the NIRS: nicon & decon (see publication below)
PyTorch models (via extensions)
JAX models (via extensions)
Model Fine-tuning:
Hyperparameter optimization with Optuna
Grid search and random search
Cross-validation strategies
Visualization:
Preprocessing effect visualization
Model performance visualization
Feature importance analysis
Classification metrics
Residual analysis
Synthetic Data Generation:
Physically-motivated NIRS spectra (Beer-Lambert law)
Predefined spectral components (water, protein, lipid, etc.)
Configurable complexity levels for testing
Classification and regression targets
Export to CSV for loader testing
Installation
Basic Installation
pip install nirs4all
This installs the core library with scikit-learn support. Deep learning frameworks are optional.
With Additional ML Frameworks
# With TensorFlow support (CPU)
pip install nirs4all[tensorflow]
# With TensorFlow support (GPU)
pip install nirs4all[gpu]
# With PyTorch support
pip install nirs4all[torch]
# With Keras support
pip install nirs4all[keras]
# With JAX support
pip install nirs4all[jax]
# With all ML frameworks
pip install nirs4all[all]
# With all ML frameworks and GPU support for TensorFlow
pip install nirs4all[all-gpu]
Development Installation
For developers who want to contribute:
git clone https://github.com/gbeurier/nirs4all.git
cd nirs4all
pip install -e .[dev]
Research Applications
NIRS4ALL has been successfully used in published research:
Houngbo, M. E., Desfontaines, L., Diman, J. L., Arnau, G., Mestres, C., Davrieux, F., Rouan, L., Beurier, G., Marie‐Magdeleine, C., Meghar, K., Alamu, E. O., Otegbayo, B. O., & Cornet, D. (2024). Convolutional neural network allows amylose content prediction in yam (Dioscorea alata L.) flour using near infrared spectroscopy. Journal of the Science of Food and Agriculture, 104(8), 4915-4921. John Wiley & Sons, Ltd.
How to Cite
If you use NIRS4ALL in your research, please cite:
@software{beurier2025nirs4all,
author = {Gregory Beurier and Denis Cornet and Camille Noûs and Lauriane Rouan},
title = {nirs4all is all your nirs: Open spectroscopy for everyone},
url = {https://github.com/gbeurier/nirs4all},
version = {1.4.3},
year = {2026},
}
License
nirs4all is distributed under a dual license: by default AGPL-3.0-or-later (with GPL-3.0-or-later and CeCILL-2.1 variants available), plus a separate commercial license for closed-source use. See the LICENSE file for the full terms.