Models

This section covers model training, comparison, and optimization in NIRS4ALL.

Overview

NIRS4ALL supports a wide range of machine learning models from different frameworks. This section covers model training workflows.

🎯 Model Training

Train models with cross-validation and evaluate performance.

Model Training
⚙️ Hyperparameter Tuning

Optimize models with Optuna integration and grid search.

Hyperparameter Tuning
Native Tuning + Conformal

Use the native run(tuning=...) subset, persist tuning/conformal evidence, and apply calibrated intervals. Includes the smoke-tested tune→calibrate→predict→robustness example. Includes a native PLS example that tunes model.n_components.

Native tuning and conformal calibration
🧠 Deep Learning

Use TensorFlow, PyTorch, and JAX models in pipelines.

Deep Learning Models
AOM Models

Use AOM-PLS, AOM-Ridge, AutoSelector, Blender, and FastAOM with pipeline folds.

AOM Models
🤖 TabPFN for NIRS

Fixed-recipe TabPFN regressor that matches per-dataset HPO without it.

TabPFN for NIRS — fixed recipe (no HPO)

Supported Model Frameworks

Framework

Import

Examples

scikit-learn

Direct

PLSRegression, RandomForest, SVM

TensorFlow/Keras

nirs4all[tensorflow]

Sequential, Custom architectures

PyTorch

nirs4all[torch]

nn.Module subclasses

JAX

nirs4all[jax]

Flax/Haiku models

Quick Example

from sklearn.cross_decomposition import PLSRegression
from sklearn.model_selection import KFold

result = nirs4all.run([
    MinMaxScaler(),
    KFold(n_splits=5),
    {"model": PLSRegression(n_components=10)}
], dataset="data/")
print(f"RMSE: {result.best_rmse:.4f}")

Built-in NIRS Models

NIRS4ALL includes specialized models optimized for spectroscopy:

PLS Variants

Model

Description

AOMPLSRegressor

Adaptive Operator-Mixture PLS — auto-selects best preprocessing from operator bank

AOMPLSClassifier

AOM-PLS for classification with probability calibration

AOMRidgeRegressor

AOM-Ridge with operator-bank selection and internal CV

AOMRidgeAutoSelector

Selects the best AOM-Ridge variant under outer CV

AOMRidgeBlender

Convex blend of AOM-Ridge variants; strongest general AOM-Ridge recipe

FastAOMPLSRidge

Fast screened operator-chain AOM PLS/Ridge

POPPLSRegressor

Per-Operator-Per-component PLS — different operator per component via PRESS

POPPLSClassifier

POP-PLS for classification with probability calibration

PLSDA

PLS Discriminant Analysis

OPLS / OPLSDA

Orthogonal PLS / OPLS-DA

MBPLS

Multi-Block PLS

DiPLS

Domain-Invariant PLS

IKPLS

Improved Kernel PLS

FCKPLS

Fractional Convolution Kernel PLS

LWPLS

Locally Weighted PLS

SparsePLS

Sparse PLS

SIMPLS

SIMPLS algorithm

from nirs4all.operators.models import AOMPLSRegressor, AOMRidgeBlender, POPPLSRegressor

# Native n4m AOM-PLS: select preprocessing and component count by CV
pipeline = [
    KFold(n_splits=5),
    {"model": AOMPLSRegressor(max_components=10, cv=5)}
]

# AOM-Ridge Blender: strong split-aware operator-mixture Ridge recipe
pipeline = [
    KFold(n_splits=5),
    {
        "model": AOMRidgeBlender(outer_cv=5, inner_cv=5),
        "train_params": {"use_pipeline_folds_for_aom": "required"},
    },
]

# Native n4m POP-PLS: selects a different operator per component
pipeline = [
    KFold(n_splits=5),
    {"model": POPPLSRegressor(max_components=15, cv=5)}
]

Deep Learning

  • nicon - 1D CNN for NIR classification/regression

  • decon - 1D CNN for NIR regression

from nirs4all.operators.models import nicon, decon

pipeline = [
    MinMaxScaler(),
    KFold(n_splits=5),
    {"model": decon(n_outputs=1)}
]

See Also