cca_zoo.linearο
- class cca_zoo.linear.CCA(latent_dimensions: int = 1, copy_data=True, random_state=None)[source]ο
Bases:
rCCA
A class used to fit a simple CCA model. This model finds the linear projections of two views that maximize their correlation.
The objective function of CCA is:
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ w_1^TX_1^TX_2w_2 \}\\\end{split}\\\text{subject to:}\\w_1^TX_1^TX_1w_1=n\\w_2^TX_2^TX_2w_2=n\end{aligned}\end{align} \]- Parameters:
References
Hotelling, Harold. βRelations between two sets of variates.β Breakthroughs in statistics. Springer, New York, NY, 1992. 162-190.
Example
>>> from cca_zoo.linear import CCA >>> import numpy as np >>> rng=np.random.RandomState(0) >>> X1 = rng.random((10,5)) >>> X2 = rng.random((10,5)) >>> model = CCA() >>> model.fit((X1,X2)).score((X1,X2)) array([1.])
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') CCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') CCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') CCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.CCAEY(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=1e-09, accept_sparse=None, batch_size=None, epochs=100, learning_rate=0.1, initialization: str | callable = 'random', dataloader_kwargs=None, optimizer_kwargs=None, convergence_checking=None, patience=10, track=None, verbose=False)[source]ο
Bases:
BaseGradientModel
A class used to fit Regularized CCA by Delta-EigenGame
- Parameters:
latent_dimensions (int, optional) β Number of latent dimensions to use, by default 1
copy_data (bool, optional) β Whether to copy the data, by default True
random_state (int, optional) β Random state to use, by default None
accept_sparse (bool, optional) β Whether to accept sparse data, by default None
batch_size (int, optional) β Batch size to use, by default 1
epochs (int, optional) β Number of epochs to use, by default 1
learning_rate (float, optional) β Learning rate to use, by default 0.01
References
Chapman, James, Ana Lawry Aguila, and Lennie Wells. βA Generalized EigenGame with Extensions to Multiview Representation Learning.β arXiv preprint arXiv:2211.11323 (2022).
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') CCAEY ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') CCAEY ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') CCAEY ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.CCAGH(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=1e-09, accept_sparse=None, batch_size=None, epochs=100, learning_rate=0.1, initialization: str | callable = 'random', dataloader_kwargs=None, optimizer_kwargs=None, convergence_checking=None, patience=10, track=None, verbose=False)[source]ο
Bases:
CCAEY
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') CCAGH ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') CCAGH ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') CCAGH ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.CCASVD(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=1e-09, accept_sparse=None, batch_size=None, epochs=100, learning_rate=0.1, initialization: str | callable = 'random', dataloader_kwargs=None, optimizer_kwargs=None, convergence_checking=None, patience=10, track=None, verbose=False)[source]ο
Bases:
CCAEY
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') CCASVD ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') CCASVD ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') CCASVD ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.ElasticCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=0.001, accept_sparse=None, epochs=100, initialization: str | callable = 'uniform', early_stopping=False, verbose=None, alpha=None, l1_ratio=None, positive=None, stochastic=False)[source]ο
Bases:
DeflationMixin
,BaseIterative
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') ElasticCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') ElasticCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') ElasticCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.GCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, c: Iterable[float] | float = None, view_weights: Iterable[float] = None, eps: float = 1e-06)[source]ο
Bases:
MCCA
A class used to fit GCCA model. This model extends CCA to more than two views by optimizing the sum of correlations with a shared auxiliary vector.
The objective function of GCCA is:
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ \sum_iw_i^TX_i^TT \}\\\end{split}\\\text{subject to:}\\T^TT=1\end{aligned}\end{align} \]where \(T\) is the auxiliary vector.
References
Tenenhaus, Arthur, and Michel Tenenhaus. βRegularized generalized canonical correlation analysis.β Psychometrika 76.2 (2011): 257.
Examples
>>> from cca_zoo.linear import GCCA >>> import numpy as np >>> rng=np.random.RandomState(0) >>> X1 = rng.random((10,5)) >>> X2 = rng.random((10,5)) >>> X3 = rng.random((10,5)) >>> model = GCCA() >>> model.fit((X1,X2,X3)).score((X1,X2,X3)) array([0.97229856])
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, K=None, **kwargs)[source]ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, K: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') GCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.- Parameters:
- Returns:
self β The updated object.
- Return type:
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') GCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') GCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.GRCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, eps=0.001, c: float = 0, mu: float = 0)[source]ο
Bases:
MCCA
Grouped Regularized Canonical Correlation Analysis
- Parameters:
latent_dimensions (int, default=1) β Number of latent dimensions to use
copy_data (bool, default=True) β Whether to copy the data
random_state (int, default=None) β Random state for initialisation
eps (float, default=1e-3) β Tolerance for convergence
c (float, default=0) β Regularization parameter for the group means
mu (float, default=0) β Regularization parameter for the group sizes
References
Tuzhilina, Elena, Leonardo Tozzi, and Trevor Hastie. βCanonical correlation analysis in high dimensions with structured regularization.β Statistical Modelling (2021): 1471082X211041033.
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, feature_groups=None, **kwargs)[source]ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, feature_groups: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') GRCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.- Parameters:
- Returns:
self β The updated object.
- Return type:
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') GRCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') GRCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.MCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, c: Iterable[float] | float = None, accept_sparse=None, eps: float = 1e-06, pca: bool = True)[source]ο
Bases:
BaseModel
A class used to fit Regularised CCA (canonical ridge) model. This model adds a regularization term to the CCA objective function to avoid overfitting and improve stability. It uses PCA to perform the optimization efficiently for high dimensional data.
The objective function of regularised CCA is:
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ w_1^TX_1^TX_2w_2 \}\\\end{split}\\\text{subject to:}\\(1-c_1)w_1^TX_1^TX_1w_1+c_1w_1^Tw_1=n\\(1-c_2)w_2^TX_2^TX_2w_2+c_2w_2^Tw_2=n\end{aligned}\end{align} \]where \(c_i\) are the regularization parameters for each view.
- Parameters:
latent_dimensions (int, optional) β Number of latent dimensions to use, by default 1
copy_data (bool, optional) β Whether to copy the data, by default True
random_state (int, optional) β Random state, by default None
c (Union[Iterable[float], float], optional) β Regularisation parameter, by default None
accept_sparse (Union[bool, str], optional) β Whether to accept sparse data, by default None
References
Vinod, Hrishikesh _D. βCanonical ridge and econometrics of joint production.β Journal of econometrics 4.2 (1976): 147-166.
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)[source]ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') MCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') MCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') MCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.MPLS(latent_dimensions: int = 1, copy_data=True, random_state=None)[source]ο
Bases:
MCCA
,PLSMixin
A class used to fit a mutiview PLS model. This model finds the linear projections of two views that maximize their covariance.
Implements PLS by inheriting regularised CCA with maximal regularisation. This is equivalent to solving the following optimization problem:
- Parameters:
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') MPLS ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') MPLS ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') MPLS ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PCACCA(latent_dimensions=1, copy_data=True, random_state=None, c: Iterable[float] | float = None, eps=1e-09, percent_variance=0.99)[source]ο
Bases:
MCCA
Principal Component Analysis CCA
Data driven PCA on each view followed by CCA on the PCA components. Keep percentage of variance
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') PCACCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PCACCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PCACCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PLS(latent_dimensions: int = 1, copy_data=True, random_state=None)[source]ο
Bases:
rCCA
,PLSMixin
A class used to fit a simple PLS model. This model finds the linear projections of two views that maximize their covariance.
Implements PLS by inheriting regularised CCA with maximal regularisation. This is equivalent to solving the following optimization problem:
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ w_1^TX_1^TX_2w_2 \}\\\end{split}\\\text{subject to:}\\w_1^Tw_1=1\\w_2^Tw_2=1\end{aligned}\end{align} \]- Parameters:
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') PLS ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PLS ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PLS ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PLSEY(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=1e-09, accept_sparse=None, batch_size=None, epochs=100, learning_rate=0.1, initialization: str | callable = 'random', dataloader_kwargs=None, optimizer_kwargs=None, convergence_checking=None, patience=10, track=None, verbose=False)[source]ο
Bases:
CCAEY
,PLSMixin
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') PLSEY ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PLSEY ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PLSEY ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PLSSVD(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=1e-09, accept_sparse=None, batch_size=None, epochs=100, learning_rate=0.1, initialization: str | callable = 'random', dataloader_kwargs=None, optimizer_kwargs=None, convergence_checking=None, patience=10, track=None, verbose=False)[source]ο
Bases:
CCASVD
,PLSMixin
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') PLSSVD ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PLSSVD ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PLSSVD ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PLSStochasticPower(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=1e-09, accept_sparse=None, batch_size=None, epochs=100, learning_rate=0.1, initialization: str | callable = 'random', dataloader_kwargs=None, optimizer_kwargs=None, convergence_checking=None, patience=10, track=None, verbose=False)[source]ο
Bases:
PLSEY
,PLSMixin
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') PLSStochasticPower ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PLSStochasticPower ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PLSStochasticPower ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PLS_ALS(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=0.001, accept_sparse=None, epochs=100, initialization: str | callable = 'random', early_stopping=False, verbose=True)[source]ο
Bases:
DeflationMixin
,BaseIterative
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') PLS_ALS ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PLS_ALS ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PLS_ALS ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PRCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, eps=0.001, c=0)[source]ο
Bases:
MCCA
Partially Regularized Canonical Correlation Analysis
- Parameters:
latent_dimensions (int, optional) β Number of latent dimensions to use, by default 1
copy_data (bool, optional) β Whether to copy the data, by default True
random_state (int, optional) β Random state for reproducibility, by default None
eps (float, optional) β Tolerance for convergence, by default 1e-3
c (Union[Iterable[float], float], optional) β Regularisation parameter, by default None
References
Tuzhilina, Elena, Leonardo Tozzi, and Trevor Hastie. βCanonical correlation analysis in high dimensions with structured regularization.β Statistical Modelling (2021): 1471082X211041033.
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, idxs=None, **kwargs)[source]ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
idxs (list/tuple of integers indicating which features from each view are the partially regularised features) β
kwargs (any additional keyword arguments required by the given model) β
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, idxs: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') PRCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.- Parameters:
- Returns:
self β The updated object.
- Return type:
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PRCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') PRCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.PartialCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, c: Iterable[float] | float = None, accept_sparse=None, eps: float = 1e-06, pca: bool = True)[source]ο
Bases:
MCCA
A class used to fit a partial CCA model. This model extends CCA to account for confounding variables that may affect the correlation between views.
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ w_1^TX_1^TX_2w_2 \}\\\end{split}\\\text{subject to:}\\w_i^TX_i^TX_iw_i=1\\w_i^TX_i^TZ=0\end{aligned}\end{align} \]References
Rao, B. Raja. βPartial canonical correlations.β Trabajos de estadistica y de investigaciΓ³n operativa 20.2-3 (1969): 211-219.
Example
>>> from cca_zoo.linear import PartialCCA >>> X1 = np.random.rand(10,5) >>> X2 = np.random.rand(10,5) >>> partials = np.random.rand(10,3) >>> model = PartialCCA() >>> model.fit((X1,X2),partials=partials).score((X1,X2)) array([0.99993046])
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, partials=None, **kwargs)[source]ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, partials: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') PartialCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.- Parameters:
- Returns:
self β The updated object.
- Return type:
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') PartialCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, partials: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') PartialCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.- Parameters:
- Returns:
self β The updated object.
- Return type:
- transform(views: Iterable[ndarray], partials=None, **kwargs)[source]ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.SCCA_IPLS(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=0.001, accept_sparse=None, epochs=100, initialization: str | callable = 'uniform', early_stopping=False, verbose=True, alpha=None, l1_ratio=1, positive=None, stochastic=False)[source]ο
Bases:
DeflationMixin
,BaseIterative
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_IPLS ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_IPLS ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_IPLS ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.SCCA_PMD(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=0.001, accept_sparse=None, epochs=100, initialization: str | callable = 'pls', early_stopping=False, verbose=True, tau=None, positive=False)[source]ο
Bases:
DeflationMixin
,BaseIterative
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_PMD ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_PMD ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_PMD ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.SCCA_Parkhomenko(latent_dimensions: int = 1, copy_data=True, random_state=None, tol=0.001, accept_sparse=None, epochs=100, initialization: str | callable = 'pls', early_stopping=False, verbose=True, tau=None)[source]ο
Bases:
DeflationMixin
,BaseIterative
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_Parkhomenko ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_Parkhomenko ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_Parkhomenko ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.SCCA_Span(latent_dimensions: int = 1, epochs: int = 100, copy_data=True, initialization: str = 'pls', tol: float = 0.001, regularisation='l0', tau: Iterable[float | int] | float | int = None, rank=1, positive: Iterable[bool] | bool = None, random_state=None, verbose=True, early_stopping=False)[source]ο
Bases:
DeflationMixin
,BaseIterative
Fits a Sparse CCA model using SpanCCA.
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{\sum_i\sum_{j\neq i} \|X_iw_i-X_jw_j\|^2 + \text{l1_ratio}\|w_i\|_1\}\\\end{split}\\\text{subject to:}\\w_i^TX_i^TX_iw_i=1\end{aligned}\end{align} \]References
Asteris, Megasthenis, et al. βA simple and provable algorithm for sparse diagonal CCA.β International Conference on Machine Learning. PMLR, 2016.
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_Span ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_Span ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') SCCA_Span ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.TCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, c: Iterable[float] | float = None, accept_sparse=None, eps: float = 1e-06, pca: bool = True)[source]ο
Bases:
MCCA
A class used to fit TCCA model. This model extends MCCA to higher order correlations by using tensor products of the views.
The objective function of TCCA is:
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ w_1^TX_1^T\otimes w_2^TX_2^T\otimes \cdots \otimes w_m^TX_m^Tw \}\\\end{split}\\\text{subject to:}\\w_i^TX_i^TX_iw_i=1\end{aligned}\end{align} \]where \(\otimes\) denotes the Kronecker product.
References
Kim, Tae-Kyun, Shu-Fai Wong, and Roberto Cipolla. βTensor canonical correlation analysis for action classification.β 2007 IEEE Conference on Computer Vision and Pattern Recognition. IEEE, 2007
Examples
>>> from cca_zoo.linear import TCCA >>> rng=np.random.RandomState(0) >>> X1 = rng.random((10,5)) >>> X2 = rng.random((10,5)) >>> X3 = rng.random((10,5)) >>> model = TCCA() >>> model.fit((X1,X2,X3)).score((X1,X2,X3)) array([1.14595755])
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- correlations(views: Iterable[ndarray], **kwargs)[source]ο
Predicts the correlation for the given data using the fit model
- Parameters:
views β list/tuple of numpy arrays or array likes with the same number of rows (samples)
kwargs β any additional keyword arguments required by the given model
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)[source]ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], **kwargs)[source]ο
Returns the higher order correlations in each dimension
- Parameters:
views β list/tuple of numpy arrays or array likes with the same number of rows (samples)
kwargs β any additional keyword arguments required by the given model
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') TCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') TCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') TCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- class cca_zoo.linear.rCCA(latent_dimensions: int = 1, copy_data=True, random_state=None, c: Iterable[float] | float = None, accept_sparse=None, eps: float = 1e-06, pca: bool = True)[source]ο
Bases:
MCCA
A class used to fit Regularised CCA (canonical ridge) model. This model adds a regularization term to the CCA objective function to avoid overfitting and improve stability. It uses PCA to perform the optimization efficiently for high dimensional data.
The objective function of regularised CCA is:
\[ \begin{align}\begin{aligned}\begin{split}w_{opt}=\underset{w}{\mathrm{argmax}}\{ w_1^TX_1^TX_2w_2 \}\\\end{split}\\\text{subject to:}\\(1-c_1)w_1^TX_1^TX_1w_1+c_1w_1^Tw_1=n\\(1-c_2)w_2^TX_2^TX_2w_2+c_2w_2^Tw_2=n\end{aligned}\end{align} \]where \(c_i\) are the regularization parameters for each view.
References
Vinod, Hrishikesh _D. βCanonical ridge and econometrics of joint production.β Journal of econometrics 4.2 (1976): 147-166.
- canonical_loadings(views: Iterable[ndarray], normalize: bool = True, **kwargs) List[ndarray] ο
Calculate canonical loadings for each view.
Canonical loadings represent the correlation between the original variables in a view and their respective canonical variates. Canonical variates are linear combinations of the original variables formed to maximize the correlation with canonical variates from another view.
Mathematically, given two views (X_i), canonical variates from the views are:
(Z_i = w_i^T X_i)
The canonical loading for a variable in (X_i) is the correlation between that variable and (Z_i).
- Parameters:
views (list/tuple of numpy arrays) β Each array corresponds to a view. All views must have the same number of rows (observations).
- Returns:
loadings β Canonical loadings for each view. High absolute values indicate that the respective original variables play a significant role in defining the canonical variate.
- Return type:
list of numpy arrays
- explained_covariance(views: Iterable[ndarray]) ndarray ο
Calculates the covariance matrix of the transformed components for each view.
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
- Returns:
explained_covariances β Covariance matrices for the transformed components of each view.
- Return type:
list of numpy arrays
- explained_covariance_cumulative(views: Iterable[ndarray]) ndarray ο
Calculates the cumulative explained covariance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance(views: Iterable[ndarray]) List[ndarray] ο
Calculates the variance captured by each latent dimension for each view.
- Returns:
transformed_vars
- Return type:
list of numpy arrays
- explained_variance_cumulative(views: Iterable[ndarray]) List[ndarray] ο
Calculates the cumulative explained variance ratio for each latent dimension for each view.
- Returns:
cumulative_ratios
- Return type:
list of numpy arrays
- explained_variance_ratio(views: Iterable[ndarray]) List[ndarray] ο
Calculates the ratio of the variance captured by each latent dimension to the total variance for each view.
- Returns:
explained_variance_ratios
- Return type:
list of numpy arrays
- fit(views: Iterable[ndarray], y=None, **kwargs)ο
Fits the model to the given data
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
self
- Return type:
- fit_transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
Fits the model to the given data and returns the transformed views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays
- get_metadata_routing()ο
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing β A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)ο
Get parameters for this estimator.
- property loadings: List[ndarray]ο
Compute and return loadings for each view. These are cached for performance optimization.
In the context of the cca-zoo models, loadings are the normalized weights. Due to the structure of these models, weight vectors are normalized such that wβXβXw = 1, as opposed to wβw = 1, which is commonly used in PCA. As a result, when computing the loadings, the weights are normalized to have unit norm, ensuring that the loadings range between -1 and 1.
Itβs essential to differentiate between these loadings and canonical loadings. The latter are correlations between the original variables and their corresponding canonical variates.
- Returns:
Loadings for each view.
- Return type:
List[np.ndarray]
- pairwise_correlations(views: Iterable[ndarray], **kwargs) ndarray ο
Returns the pairwise correlations between the views in each dimension
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
pairwise_correlations
- Return type:
numpy array of shape (n_views, n_views, latent_dimensions)
- score(views: Iterable[ndarray], y: Any | None = None, **kwargs) float ο
Returns the average pairwise correlation between the views
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
y (None) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
score
- Return type:
- set_fit_request(*, views: bool | None | str = '$UNCHANGED$') rCCA ο
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_params(**params)ο
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:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance
- set_score_request(*, views: bool | None | str = '$UNCHANGED$') rCCA ο
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- set_transform_request(*, views: bool | None | str = '$UNCHANGED$') rCCA ο
Request metadata passed to the
transform
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.
- transform(views: Iterable[ndarray], **kwargs) List[ndarray] ο
- Parameters:
views (list/tuple of numpy arrays or array likes with the same number of rows (samples)) β
kwargs (any additional keyword arguments required by the given model) β
- Returns:
transformed_views
- Return type:
list of numpy arrays