Implementation:Scikit learn Scikit learn PLSRegression
| Knowledge Sources | |
|---|---|
| Domains | Cross Decomposition, Regression |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for Partial Least Squares regression provided by scikit-learn.
Description
PLSRegression, also known as PLS2 or PLS1 depending on the number of targets, is a cross-decomposition method that projects both the predictors (X) and the response (y) into a lower-dimensional space of latent variables while maximizing the covariance between them. It combines dimensionality reduction with regression, making it particularly effective when predictors are highly collinear or when there are more features than samples. The module also provides PLSCanonical and PLSSVD as related cross-decomposition algorithms.
Usage
Use PLSRegression when you have high-dimensional, possibly collinear predictor variables and need to build a regression model. It is commonly applied in chemometrics, spectroscopy, genomics, and neuroimaging where the number of features often exceeds the number of samples and ordinary least squares regression would be ill-conditioned.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/cross_decomposition/_pls.py
Signature
class PLSRegression(_PLS):
def __init__(
self,
n_components=2,
*,
scale=True,
max_iter=500,
tol=1e-06,
copy=True,
):
Import
from sklearn.cross_decomposition import PLSRegression
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| n_components | int | No | Number of components to keep. Should be in [1, n_features] (default=2). |
| scale | bool | No | Whether to scale X and y (default=True). |
| max_iter | int | No | Maximum number of iterations for the power method (default=500). |
| tol | float | No | Convergence tolerance for the power method (default=1e-06). |
| copy | bool | No | Whether to copy X and y in fit before centering/scaling (default=True). |
Outputs
| Name | Type | Description |
|---|---|---|
| x_weights_ | ndarray of shape (n_features, n_components) | Left singular vectors of the cross-covariance matrices. |
| y_weights_ | ndarray of shape (n_targets, n_components) | Right singular vectors of the cross-covariance matrices. |
| x_loadings_ | ndarray of shape (n_features, n_components) | Loadings of X. |
| y_loadings_ | ndarray of shape (n_targets, n_components) | Loadings of y. |
| x_scores_ | ndarray of shape (n_samples, n_components) | Transformed training samples. |
| y_scores_ | ndarray of shape (n_samples, n_components) | Transformed training targets. |
| x_rotations_ | ndarray of shape (n_features, n_components) | Projection matrix used to transform X. |
| y_rotations_ | ndarray of shape (n_targets, n_components) | Projection matrix used to transform y. |
| coef_ | ndarray of shape (n_targets, n_features) | Coefficients of the linear model. |
| intercept_ | ndarray of shape (n_targets,) | Intercepts of the linear model. |
| n_features_in_ | int | Number of features seen during fit. |
Usage Examples
Basic Usage
import numpy as np
from sklearn.cross_decomposition import PLSRegression
X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=float)
y = np.array([1, 2, 3, 4], dtype=float)
pls = PLSRegression(n_components=2)
pls.fit(X, y)
X_transformed = pls.transform(X)
y_pred = pls.predict(X)
print(X_transformed.shape) # (4, 2)
print(y_pred.shape) # (4, 1)
print(pls.coef_.shape) # (1, 3)