PLSSVD#
- classsklearn.cross_decomposition.PLSSVD(n_components=2, *, scale=True, copy=True)[source] #
Partial Least Square SVD.
This transformer simply performs a SVD on the cross-covariance matrix
X'y. It is able to project both the training dataXand the targetsy. The training dataXis projected on the left singular vectors, while the targets are projected on the right singular vectors.Read more in the User Guide.
Added 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
Xandy.- copybool, default=True
Whether to copy
Xandyin fit before applying centering, and potentially scaling. IfFalse, 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
Xintransform.- y_weights_ndarray of (n_targets, n_components)
The right singular vectors of the SVD of the cross-covariance matrix. Used to project
Xintransform.- n_features_in_int
Number of features seen during fit.
- feature_names_in_ndarray of shape (
n_features_in_,) Names of features seen during fit. Defined only when
Xhas feature names that are all strings.Added in version 1.0.
See also
PLSCanonicalPartial Least Squares transformer and regressor.
CCACanonical Correlation Analysis.
Examples
>>> importnumpyasnp >>> fromsklearn.cross_decompositionimport 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))
- 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.
- Returns:
- selfobject
Fitted estimator.
- 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_transformedify is not None,(X_transformed, y_transformed)otherwise.
- get_feature_names_out(input_features=None)[source] #
Get output feature names for transformation.
The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are:
["class_name0", "class_name1", "class_name2"].- Parameters:
- input_featuresarray-like of str or None, default=None
Only used to validate feature names with the names seen in
fit.
- Returns:
- feature_names_outndarray of str objects
Transformed feature names.
- get_metadata_routing()[source] #
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- 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_output(*, transform=None)[source] #
Set output container.
See Introducing the set_output API for an example on how to use the API.
- Parameters:
- transform{"default", "pandas", "polars"}, default=None
Configure output of
transformandfit_transform."default": Default output format of a transformer"pandas": DataFrame output"polars": Polars outputNone: Transform configuration is unchanged
Added in version 1.4:
"polars"option was added.
- Returns:
- selfestimator instance
Estimator instance.
- 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:
- x_scoresarray-like or tuple of array-like
The transformed data
X_transformedify is not None,(X_transformed, y_transformed)otherwise.