sklearn.cross_decomposition.PLSSVD

class sklearn.cross_decomposition.PLSSVD(n_components=2, *, scale=True, copy=True)[source]

Partial Least Square SVD.

This transformer simply performs a SVD on the crosscovariance matrix X’Y. It is able to project both the training data X and the targets Y. The training data X is projected on the left singular vectors, while the targets are projected on the right singular vectors.

Read more in the User Guide.

New in version 0.8.

Parameters
n_componentsint, default=2

The number of components to keep. Should be in [1, min(n_samples, n_features, n_targets)].

scalebool, default=True

Whether to scale X and Y.

copybool, default=True

Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.

Attributes
x_weights_ndarray of shape (n_features, n_components)

The left singular vectors of the SVD of the cross-covariance matrix. Used to project X in transform.

y_weights_ndarray of (n_targets, n_components)

The right singular vectors of the SVD of the cross-covariance matrix. Used to project X in transform.

x_scores_ndarray of shape (n_samples, n_components)

The transformed training samples.

Deprecated since version 0.24: x_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.

y_scores_ndarray of shape (n_samples, n_components)

The transformed training targets.

Deprecated since version 0.24: y_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.

n_features_in_int

Number of features seen during fit.

See also

PLSCanonical
CCA

Examples

>>> import numpy as np
>>> from sklearn.cross_decomposition import PLSSVD
>>> X = np.array([[0., 0., 1.],
...               [1., 0., 0.],
...               [2., 2., 2.],
...               [2., 5., 4.]])
>>> Y = np.array([[0.1, -0.2],
...               [0.9, 1.1],
...               [6.2, 5.9],
...               [11.9, 12.3]])
>>> pls = PLSSVD(n_components=2).fit(X, Y)
>>> X_c, Y_c = pls.transform(X, Y)
>>> X_c.shape, Y_c.shape
((4, 2), (4, 2))

Methods

fit(X, Y)

Fit model to data.

fit_transform(X[, y])

Learn and apply the dimensionality reduction.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

transform(X[, Y])

Apply the dimensionality reduction.

fit(X, Y)[source]

Fit model to data.

Parameters
Xarray-like of shape (n_samples, n_features)

Training samples.

Yarray-like of shape (n_samples,) or (n_samples, n_targets)

Targets.

fit_transform(X, y=None)[source]

Learn and apply the dimensionality reduction.

Parameters
Xarray-like of shape (n_samples, n_features)

Training samples.

yarray-like of shape (n_samples,) or (n_samples, n_targets), default=None

Targets.

Returns
outarray-like or tuple of array-like

The transformed data X_tranformed if Y is not None, (X_transformed, Y_transformed) otherwise.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsdict

Parameter names mapped to their values.

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters
**paramsdict

Estimator parameters.

Returns
selfestimator instance

Estimator instance.

transform(X, Y=None)[source]

Apply the dimensionality reduction.

Parameters
Xarray-like of shape (n_samples, n_features)

Samples to be transformed.

Yarray-like of shape (n_samples,) or (n_samples, n_targets), default=None

Targets.

Returns
outarray-like or tuple of array-like

The transformed data X_tranformed if Y is not None, (X_transformed, Y_transformed) otherwise.