PLSCanonical
- class sklearn.cross_decomposition.PLSCanonical(n_components=2, *, scale=True, algorithm='nipals', max_iter=500, tol=1e-06, copy=
Partial Least Squares transformer and regressor.
For a comparison between other cross decomposition algorithms, see Compare cross decomposition methods.
Read more in the User Guide.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and y.
The algorithm used to estimate the first singular vectors of the cross-covariance matrix. ‘nipals’ uses the power method while ‘svd’ will compute the whole SVD.
The maximum number of iterations of the power method when
algorithm='nipals'. Ignored otherwise.
The tolerance used as convergence criteria in the power method: the
algorithm stops whenever the squared norm of u_i - u_{i-1} is less
than tol, where u corresponds to the left singular vector.
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.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of y.
The projection matrix used to transform .
>>> from sklearn.cross_decomposition import PLSCanonical
>>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
Fit model to data.
Training vectors, where n_samples is the number of samples and
n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and
is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and
n_features is the number of predictors.
Target vectors, where is the number of samples and is the number of response variables.
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"].
Only used to validate feature names with the names seen in fit.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest encapsulating
routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Transform data back to its original space.
New data, where n_samples is the number of samples
and n_components is the number of pls components.
New target, where is the number of samples and is the number of pls components.
Predict targets of given samples.
Samples.
Whether to copy X or perform in-place normalization.
Return coefficient of determination on test data.
The coefficient of determination, , is defined as , where is the residual sum of squares and is the total sum of squares . The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of , disregarding the input features, would get a score of 0.0.
Set output container.
Refer to the user guide for more details and Introducing the set_output API for an example on how to use the API.
Configure output of transform and .
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.
Estimator parameters.
Configure whether metadata should be requested to be passed to the method.
Configure whether metadata should be requested to be passed to the method.
Configure whether metadata should be requested to be passed to the method.
Apply the dimension reduction.
Samples to transform.
Target vectors.
The projection matrix used to transform y.
The coefficients of the linear model such that y is approximated as
y = X @ coef_.T + intercept_.
The intercepts of the linear model such that y is approximated as
y = X @ coef_.T + intercept_.
Number of iterations of the power method, for each
component. Empty if algorithm='svd'.
Number of features seen during fit.
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
n_targetsFitted model.
n_samplesn_targetsReturn x_scores if y is not given, (x_scores, y_scores) otherwise.
Transformed feature names.
n_samplesn_componentsReturn the reconstructed X data.
Return the reconstructed X target. Only returned when y is given.
This transformation will only be exact if n_components=n_features.
Returns predicted values.
This call requires the estimation of a matrix of shape
(n_features, n_targets), which may be an issue in high dimensional
space.
((y_true - y_pred)** 2).sum()((y_true - y_true.mean()) ** 2).sum()yTest samples. For some estimators this may be a precomputed
kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), where n_samples_fitted
is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
of self.predict(X) w.r.t. y.
The score used when calling score on a regressor uses
multioutput='uniform_average' from version 0.23 to keep consistent
with default value of r2_score.
This influences the score method of all the multioutput
regressors (except for
MultiOutputRegressor).
"default": Default output format of a transformer
"pandas": DataFrame output
"polars": Polars output
None: Transform configuration is unchanged
Estimator instance.
Estimator instance.
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 (see sklearn.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 to predict if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to predict.
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.
Metadata routing for copy parameter in predict.
The updated object.
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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to score.
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.
Metadata routing for sample_weight parameter in score.
The updated object.
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 (see sklearn.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 to transform if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to transform.
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.
Metadata routing for copy parameter in transform.
The updated object.
Whether to copy X and y, or perform in-place normalization.
Return x_scores if y is not given, (x_scores, y_scores) otherwise.