Open Lab/Regression & Calibration · Method
Partial Least Squares Regression
PLSR
A two-block latent-variable regression method that constructs predictive directions using the relationship between the predictor matrix X and the response matrix Y.
What is PLS regression?
Partial least squares regression, often written PLSR and also called PLS, is a two-block latent-variable method that relates a predictor matrix to a response matrix (Geladi and Kowalski 1986; Wold, Sjostrom and Eriksson 2001). The method is used throughout chemometrics when many, collinear predictors must be connected to one or more responses.
Unlike Principal Component Analysis, which describes variation in alone, PLS constructs latent directions using information from the relationship between the and blocks. Unlike Principal Component Regression, it does not first compute PCA of and only afterwards regress on those scores.
That is not the same as collapsing PLS into a supervised form of PCA. PCA and PLS have different objectives. PCA seeks high-variance directions in . PLS methods construct latent directions so that projected and quantities have strong covariance under the chosen formulation (scikit-learn cross-decomposition user guide; de Jong 1993).
Why use PLS?
Spectral and other chemometric predictor matrices often have more variables than independent samples and strong collinearity among wavelengths or channels. Direct Multiple Linear Regression then operates in a poorly conditioned original-variable space (Wold et al. 2001; Geladi and Kowalski 1986).
PCR reduces without using . A high-variance direction in may be weakly related to the response, and a lower-variance direction may be the one that matters for prediction (Haaland and Thomas 1988; scikit-learn). PLS is useful in that setting because component construction uses X-Y information. That does not mean PLS always needs fewer components than PCR, or that it always predicts better.
How does PLS work?
Write and . PLS1 is the single-response case . PLS2 models responses jointly. Separate PLS1 fits are not the same model as one joint PLS2 fit; the latent structure can differ (scikit-learn).
Geladi and Kowalski formulate the tutorial around mean-centered blocks. Scaling is a separate preprocessing choice. It depends on the variables and the application. See Normalization & Scaling. PLS does not always require autoscaling, and it should not be described as a method that must never be scaled.
For retained latent variables the two-block representation of the centered blocks is
with X scores , Y scores , X loadings , Y loadings , and residuals and . Wold, Sjostrom and Eriksson describe PLSR as relating X and Y while also modelling the structure of both blocks. The scikit-learn cross-decomposition user guide writes the corresponding rank-one reconstruction after sequential extraction. X weights define directions used to construct scores. Loadings describe how the blocks relate to those scores in the decomposition. Weights, scores, and loadings are different quantities. They are not interchangeable with regression coefficients.
For a current centered residual block, a score may be written . After sequential extraction this is not automatically for the original without a projection or rotation matrix. Software stores that mapping separately.
PLSR is the modeling method. NIPALS and SIMPLS are algorithms used to compute PLS models. They are not synonyms for PLS. NIPALS is documented on the NIPALS page. de Jong introduced SIMPLS as an alternative that forms factors as linear combinations of the original variables and avoids the explicit deflation of both data matrices used in NIPALS-style formulations (de Jong 1993). MATLAB plsregress uses SIMPLS (MathWorks). scikit-learn PLSRegression is documented as a NIPALS-related regression-mode estimator, not as SIMPLS (scikit-learn).
The integer is a hyperparameter. Do not choose it from training fit alone, from a universal X-variance percentage, or from the number of analytes. For prediction, evaluate by validation with preprocessing and PLS fitted inside each training fold. Do not use a held-out test set to choose .
Mathematics & algorithm
The identities below use two-block notation for the centered blocks. Sequential deflation is the classical NIPALS-style description. It is not the SIMPLS algorithm used by MATLAB plsregress. Covariance objectives are formulation-dependent. They are not a single universal definition of every PLS variant.
Blocks and centering
- number of observations
- number of predictor variables
- number of response variables
Interpretation
Geladi and Kowalski work with mean-centered variables. Scaling, if used, is a separate transformation stored from training data and applied to new rows. MATLAB plsregress centers X and Y when the intercept is included and does not rescale columns. scikit-learn PLSRegression centers and, by default, also scales.
Latent-variable decomposition
- X scores
- Y scores
- X loadings
- Y loadings
Interpretation
This is the two-block representation of the centered blocks. Wold, Sjostrom and Eriksson describe PLSR as relating X and Y while also modelling the structure of both. The scikit-learn cross-decomposition user guide writes the corresponding rank-one reconstruction after sequential extraction. The displayed identities describe fitted latent structure. They are not themselves a complete numerical algorithm.
Weights, scores, and cross-block covariance
- X weight for component a
- X score for component a
- Y-side weight in two-block formulations
Interpretation
Equation 6 applies to the current residual block, not automatically to the original after several sequential components. Two-block methods choose directions so that projected and quantities have strong covariance, for example through , subject to the normalization of that formulation. That is not the PCA objective of maximizing variance of .
Sequential X deflation
Interpretation
This rank-one residual update is the sequential X-block deflation written in the scikit-learn cross-decomposition user guide. Regression-oriented Y deflation uses the X score rather than the Y score in some estimators, including scikit-learn PLSRegression. de Jong introduced SIMPLS so that factors are formed from the original variables and the NIPALS-style construction of deflated data matrices is avoided. Do not treat those residual conventions as identical.
Projection and prediction
- training-preprocessed X: centered, and column-scaled if that option is used
- projection matrix mapping preprocessed X to scores
- predictor-space coefficient matrix in centered coordinates
Interpretation
is not the same object as . If columns are not scaled, equals and . scikit-learn PLSRegression scales by default, so x_rotations_ maps the internally scaled centered , not . After restoring training means, single-response prediction has the intercept form in equations 11 and 12. On scikit-learn 1.6.1, intercept_ is the response mean and predict centers before applying coef_. Do not write intercept_ + coef_ with raw . MATLAB plsregress returns BETA including an intercept row when Intercept is true, so . Use the software prediction API. Do not assume scikit-learn and MATLAB expose identical intermediate matrices.
PLS Regression Workflow
Inputpredictor matrix X, response matrix Y, number of components A
OutputPLS model, latent representation, regression coefficients, predictions
- 01learn required centering and scaling parameters from training data
- 02transform training X and Y using those training parameters
- 03initialize the PLS model with the transformed X and Y blocks
- 04for
- 05derive a latent X direction using X-Y relationship information
- 06compute the corresponding X score
- 07estimate the component loadings and modeled contribution
- 08update the residual representation according to the selected PLS algorithm
- 09assemble the A-component latent-variable regression model
- 10compute regression coefficients for prediction
- 11for new X, apply training preprocessing, project with the fitted model, and predict Y
- 12restore the response scale if required
- 13return predictions and model quantities
Conceptual workflow. Numerical details depend on the PLS algorithm. This is not a numerical implementation of NIPALS or SIMPLS. The NIPALS page contains the iterative algorithm used here. New observations use training preprocessing only.
Visual example
Same UCI Wine calibration as the PCR page: alcohol from the other 12 variables, same five-fold splits, StandardScaler inside each training fold. PLS uses scale=False after that scaler. The starred RMSECV is the lowest mean of fold RMSEs on this single CV path, matching cross_val_score. It is not the pooled RMSECV of the Cross-Validation page, and it is not a nested estimate of a component-selection rule. Lowest PLS RMSECV is 0.561 at . PCR is an overlay under the same protocol, not a claim that one method always wins.
Code
The public Python implementation is scikit-learn PLSRegression. The estimator default is scale=True, which centers and scales both blocks. Set scale=False for centering only. Compare PCR and PLS only under a stated shared preprocessing convention. Do not let software defaults decide the experiment silently.
x_weights_, x_loadings_, and x_rotations_ are different matrices. Weights are the left singular vectors of the cross-covariance matrices at each iteration. Loadings belong to the X decomposition. Rotations are the projection matrix used by transform. Prediction uses predict. Single-response may return a 1D array. Multivariate keeps all columns. Do not flatten a PLS2 prediction to one column.
Cross validation calls cross_val_score on the estimator so that scaling and PLS are refit inside each training fold. Do not transform the full matrix first and then cross validate a regressor on those scores.
MATLAB uses official plsregress, which implements SIMPLS. With the default intercept, MathWorks centers and and does not rescale columns. If standardized variables are required, scale them explicitly, for example with zscore, using training parameters on new data. Prediction with intercept is . Intermediate weights and loadings from MATLAB and scikit-learn should not be expected to match under every configuration.
This page does not publish a handwritten NIPALS implementation. That belongs on the NIPALS resource.
import numpy as npfrom sklearn.cross_decomposition import PLSRegressionfrom sklearn.model_selection import KFold, cross_val_score def make_pls(n_components, scale=True): n_components = int(n_components) if n_components < 1: raise ValueError("n_components must be a positive integer.") return PLSRegression(n_components=n_components, scale=scale) def _validate_xy(X, Y): X = np.asarray(X, dtype=float) Y = np.asarray(Y, dtype=float) if X.ndim != 2: raise ValueError("X must be a 2D array of samples by variables.") if Y.ndim == 1: Y_work = Y.reshape(-1, 1) one_d = True elif Y.ndim == 2: Y_work = Y one_d = False else: raise ValueError("Y must be a 1D vector or a 2D array of samples by responses.") if X.shape[0] != Y_work.shape[0]: raise ValueError("X and Y must have the same number of observations.") if not np.all(np.isfinite(X)) or not np.all(np.isfinite(Y_work)): raise ValueError("X and Y must contain only finite values.") return X, Y_work, one_d def fit_pls(X, Y, n_components, scale=True): X, Y_work, one_d = _validate_xy(X, Y) if n_components > min(X.shape): raise ValueError("n_components cannot exceed min(n_samples, n_features).") y_fit = Y_work.ravel() if one_d else Y_work model = make_pls(n_components, scale=scale) model.fit(X, y_fit) return model def predict_pls(model, X_new): X_new = np.asarray(X_new, dtype=float) if X_new.ndim != 2: raise ValueError("X_new must be a 2D array of samples by variables.") if not np.all(np.isfinite(X_new)): raise ValueError("X_new must contain only finite values.") return np.asarray(model.predict(X_new), dtype=float) def pls_cv_rmse(X, y, n_components, scale=True, cv=5, random_state=0): X = np.asarray(X, dtype=float) y = np.asarray(y, dtype=float).reshape(-1) if X.ndim != 2: raise ValueError("X must be a 2D array of samples by variables.") if X.shape[0] != y.shape[0]: raise ValueError("X and y must have the same number of observations.") if not np.all(np.isfinite(X)) or not np.all(np.isfinite(y)): raise ValueError("X and y must contain only finite values.") model = make_pls(n_components, scale=scale) splits = KFold(n_splits=cv, shuffle=True, random_state=random_state) scores = cross_val_score( model, X, y, cv=splits, scoring="neg_root_mean_squared_error", ) return float(-np.mean(scores)) Practical notes
- PLSR is a supervised latent-variable regression method relating X to Y.
- PLS components use information from the X-Y relationship. They are not PCA components of X.
- PLS1 is the single-response case. PLS2 models several responses jointly. The two are not interchangeable.
- Weights, scores, and loadings are different quantities. Weights are not loadings, and neither is a causal coefficient.
- PLSR can be useful with many and strongly correlated predictors. It does not universally dominate MLR or PCR.
- Scaling is a modeling choice. scikit-learn PLSRegression scales by default. MATLAB plsregress centers with an intercept and does not rescale columns.
- The number of latent variables must be selected. Training fit is not a sufficient selection rule.
- Cross validation must include preprocessing and PLS fitting inside each training fold.
- Latent variables are mathematical model quantities. A loading peak or a large weight does not by itself identify a chemical species or prove causality.
- NIPALS and SIMPLS are algorithms for computing PLS models. They are not synonyms for PLSR, and they are not identical to each other.
References
- 1.
Geladi, P., & Kowalski, B. R. (1986). Partial least-squares regression: a tutorial. Analytica Chimica Acta, 185, 1-17.
doi:10.1016/0003-2670(86)80028-9 - 2.
Haaland, D. M., & Thomas, E. V. (1988). Partial least-squares methods for spectral analyses. 1. Relation to other quantitative calibration methods and the extraction of qualitative information. Analytical Chemistry, 60(11), 1193-1202.
doi:10.1021/ac00162a020 - 3.
Wold, S., Sjostrom, M., & Eriksson, L. (2001). PLS-regression: a basic tool of chemometrics. Chemometrics and Intelligent Laboratory Systems, 58(2), 109-130.
doi:10.1016/S0169-7439(01)00155-1 - 4.
de Jong, S. (1993). SIMPLS: an alternative approach to partial least squares regression. Chemometrics and Intelligent Laboratory Systems, 18(3), 251-263.
doi:10.1016/0169-7439(93)85002-X - 5.
scikit-learn Developers (n.d.). PLSRegression and Cross decomposition. scikit-learn documentation.
- 6.
The MathWorks, Inc. (n.d.). plsregress. MATLAB documentation.
