Canonical Correlation Analysis, also known as “Mode B” PLS.
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 maximum number of iterations of the power method.
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 X
.
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_
.
Added in version 1.1.
Number of iterations of the power method, for each component.
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.
Added in version 1.0.
See also
PLSCanonical
Partial Least Squares transformer and regressor.
PLSSVD
Partial Least Square SVD.
Examples
>>> from sklearn.cross_decomposition import CCA >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [3.,5.,4.]] >>> y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]] >>> cca = CCA(n_components=1) >>> cca.fit(X, y) CCA(n_components=1) >>> X_c, y_c = cca.transform(X, y)
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 n_targets
is the number of response variables.
Fitted model.
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 n_samples
is the number of samples and n_targets
is the number of response variables.
Return x_scores
if y
is not given, (x_scores, y_scores)
otherwise.
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
.
Transformed feature names.
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 n_samples
is the number of samples and n_components
is the number of pls components.
Return the reconstructed X
data.
Return the reconstructed X
target. Only returned when y
is given.
Notes
This transformation will only be exact if n_components=n_features
.
Predict targets of given samples.
Samples.
Whether to copy X
or perform in-place normalization.
Returns predicted values.
Notes
This call requires the estimation of a matrix of shape (n_features, n_targets)
, which may be an issue in high dimensional space.
Return coefficient of determination on test data.
The coefficient of determination, \(R^2\), is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum()
and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum()
. 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 y
, disregarding the input features, would get a \(R^2\) score of 0.0.
Test 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.
\(R^2\) of self.predict(X)
w.r.t. y
.
Notes
The \(R^2\) 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
).
Set output container.
See Introducing the set_output API for an example on how to use the API.
Configure output of transform
and fit_transform
.
"default"
: Default output format of a transformer
"pandas"
: DataFrame output
"polars"
: Polars output
None
: Transform configuration is unchanged
Added in version 1.4: "polars"
option was added.
Estimator instance.
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.
Estimator instance.
Configure whether metadata should be requested to be passed to the predict
method.
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
(seesklearn.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 topredict
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it topredict
.
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.Added in version 1.3.
Metadata routing for copy
parameter in predict
.
The updated object.
Configure whether metadata should be requested to be passed to the score
method.
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
(seesklearn.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 toscore
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it toscore
.
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.Added in version 1.3.
Metadata routing for sample_weight
parameter in score
.
The updated object.
Configure whether metadata should be requested to be passed to the transform
method.
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
(seesklearn.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 totransform
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it totransform
.
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.Added in version 1.3.
Metadata routing for copy
parameter in transform
.
The updated object.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X
and y
, or perform in-place normalization.
Return x_scores
if y
is not given, (x_scores, y_scores)
otherwise.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4