nirs4all.sklearn.pipeline module
sklearn-compatible pipeline wrapper for nirs4all.
NIRSPipeline wraps a trained nirs4all pipeline to provide sklearn’s BaseEstimator interface, enabling use with sklearn tools and SHAP.
- Important Design Decision:
NIRSPipeline is a PREDICTION-ONLY wrapper. It does NOT implement fit() for training. This is because: 1. nirs4all’s CV creates N models per fold - no single “fitted” model 2. Generator syntax expansion happens at config time, not fit time 3. Branching pipelines have multiple output paths
Training should be done via nirs4all.run(), then wrapped with from_result().
Example
>>> # Train with nirs4all
>>> result = nirs4all.run(pipeline, dataset)
>>>
>>> # Wrap for sklearn compatibility
>>> pipe = NIRSPipeline.from_result(result)
>>>
>>> # Use with SHAP
>>> explainer = shap.Explainer(pipe.predict, X_background)
>>> shap_values = explainer(X_test)
>>>
>>> # Or from exported bundle
>>> pipe = NIRSPipeline.from_bundle("exports/model.n4a")