nirs4all.operators.models.sklearn.dipls module
Dynamic PLS (DiPLS) regressor for nirs4all.
See pls.py for full documentation and usage examples.
- class nirs4all.operators.models.sklearn.dipls.DiPLS(n_components: int = 5, lags: int = 1, cv_splits: int = 7, tol: float = 1e-08, max_iter: int = 1000)[source]
Bases:
BaseEstimator,RegressorMixinDynamic PLS (DiPLS) regressor.
DiPLS extends PLS to handle dynamic systems by including time-lagged variables. It uses the trendfitter package.
- Parameters:
n_components (int, default=5) – Number of latent variables to extract.
lags (int, default=1) – Number of time lags to consider (s parameter in DiPLS).
cv_splits (int, default=7) – Number of cross-validation splits for automatic component selection.
tol (float, default=1e-8) – Convergence tolerance.
max_iter (int, default=1000) – Maximum number of iterations.
Examples
>>> from nirs4all.operators.models.sklearn.pls import DiPLS >>> import numpy as np >>> X = np.random.randn(100, 50) >>> y = np.random.randn(100) >>> model = DiPLS(n_components=5, lags=2) >>> model.fit(X, y) DiPLS(n_components=5, lags=2) >>> predictions = model.predict(X)
Notes
Requires the trendfitter package:
pip install trendfitterDiPLS is particularly useful for: - Process monitoring with temporal dependencies - NIR data collected over time - Batch process analytics
See also
sklearn.cross_decomposition.PLSRegressionStandard PLS without dynamics.
References
- fit(X, y)[source]
Fit the DiPLS model.
- Parameters:
- Returns:
self – Fitted estimator.
- Return type:
- Raises:
ImportError – If trendfitter package is not installed.
- predict(X)[source]
Predict using the DiPLS model.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
y_pred – Predicted values.
- Return type:
Notes
DiPLS uses Hankelization which may produce fewer predictions than input samples. This implementation pads the beginning with the first predicted value to maintain compatibility with sklearn cross-validation.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') DiPLS
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.