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.
Train models with cross-validation and evaluate performance.
Optimize models with Optuna integration and grid search.
Use TensorFlow, PyTorch, and JAX models in pipelines.
Supported Model Frameworks
Framework |
Import |
Examples |
|---|---|---|
scikit-learn |
Direct |
PLSRegression, RandomForest, SVM |
TensorFlow/Keras |
|
Sequential, Custom architectures |
PyTorch |
|
nn.Module subclasses |
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
Operator Catalog - All available operators
Meta-Model Stacking User Guide - Model stacking and ensembles
Developer Guide - Custom model integration