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
🧠 Deep Learning

Use TensorFlow, PyTorch, and JAX models in pipelines.

Deep Learning Models

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

pipeline = [
    MinMaxScaler(),
    KFold(n_splits=5),
    {"model": PLSRegression(n_components=10)}
]

result = nirs4all.run(pipeline, dataset="data/")
print(f"RMSE: {result.best_rmse:.4f}")

Built-in NIRS Models

NIRS4ALL includes specialized models optimized for spectroscopy:

  • nicon - 1D CNN for NIR classification

  • 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