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,RegressorMixinMultiblock 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 jaxFor GPU support:pip install jax[cuda12]
- 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.PLSRegressionStandard single-block PLS.
References
- 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:
- 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.
- 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_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MBPLS
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.