nirs4all.operators.models.sklearn.mbpls module

Multiblock PLS (MB-PLS) regressor for nirs4all.

MB-PLS fuses multiple X blocks (e.g., different preprocessing variants, multiple sensors) into a single predictive model. Each block contributes to the latent variables according to its relevance to Y.

class nirs4all.operators.models.sklearn.mbpls.MBPLS(n_components: int = 5, method: str = 'NIPALS', standardize: bool = True, max_tol: float = 1e-14, backend: str = 'numpy')[source]

Bases: BaseEstimator, RegressorMixin

Multiblock PLS (MB-PLS) regressor.

MB-PLS fuses multiple X blocks (e.g., different preprocessing variants, multiple sensors) into a single predictive model. Each block contributes to the latent variables according to its relevance to Y.

Parameters:
  • n_components (int, default=5) – Number of latent variables to extract.

  • method (str, default='NIPALS') – Decomposition method. Currently only ‘NIPALS’ is supported.

  • standardize (bool, default=True) – Whether to standardize blocks before fitting.

  • max_tol (float, default=1e-14) – Convergence tolerance for NIPALS.

  • backend (str, default='numpy') –

    Backend to use for computation. Options are: - ‘numpy’: Use NumPy backend (CPU only). - ‘jax’: Use JAX backend (supports GPU/TPU acceleration).

    Note: JAX backend only supports single-block mode.

    JAX backend requires JAX: pip install jax For GPU support: pip install jax[cuda12]

n_features_in_

Number of features seen during fit.

Type:

int

n_components_

Actual number of components used.

Type:

int

coef_

Regression coefficients.

Type:

ndarray of shape (n_features, n_targets)

Examples

>>> from nirs4all.operators.models.sklearn.pls import MBPLS
>>> import numpy as np
>>> X = np.random.randn(100, 50)
>>> y = np.random.randn(100)
>>> model = MBPLS(n_components=5)
>>> model.fit(X, y)
MBPLS(n_components=5)
>>> predictions = model.predict(X)
>>> # Multiblock usage
>>> X1 = np.random.randn(100, 30)
>>> X2 = np.random.randn(100, 20)
>>> model.fit([X1, X2], y)
>>> # JAX backend for GPU acceleration
>>> model_jax = MBPLS(n_components=5, backend='jax')

Notes

For JAX with GPU support: pip install jax[cuda12]

See also

sklearn.cross_decomposition.PLSRegression

Standard single-block PLS.

References

__repr__()[source]

Return string representation.

fit(X, y)[source]

Fit the MB-PLS model.

Parameters:
  • X (array-like of shape (n_samples, n_features) or list of arrays) – Training data. Can be a single matrix or a list of X blocks for true multiblock analysis (NumPy backend only).

  • y (array-like of shape (n_samples,) or (n_samples, n_targets)) – Target values.

Returns:

self – Fitted estimator.

Return type:

MBPLS

Raises:
  • ImportError – If mbpls package is not installed (NumPy backend), or JAX is not available (JAX backend).

  • ValueError – If backend is not ‘numpy’ or ‘jax’, or if multiblock input is used with JAX backend.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

predict(X)[source]

Predict using the MB-PLS model.

Parameters:

X (array-like of shape (n_samples, n_features) or list of arrays) – Samples to predict. Must match the format used in fit().

Returns:

y_pred – Predicted values.

Return type:

ndarray of shape (n_samples,) or (n_samples, n_targets)

set_params(**params)[source]

Set the parameters of this estimator.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

MBPLS

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MBPLS

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object

transform(X)[source]

Transform X to latent space.

Parameters:

X (array-like of shape (n_samples, n_features) or list of arrays) – Samples to transform.

Returns:

T – Latent variables (scores).

Return type:

ndarray of shape (n_samples, n_components)