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:
  • 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 seed for reproducibility, by default None

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:
  • K (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for K parameter in fit.

  • views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:
  • feature_groups (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for feature_groups parameter in fit.

  • views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:
  • 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

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:
  • 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

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:
  • idxs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for idxs parameter in fit.

  • views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:
  • partials (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for partials parameter in fit.

  • views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:
  • partials (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for partials parameter in transform.

  • views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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:

object

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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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:

float

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in score.

Returns:

self – The updated object.

Return type:

object

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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

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:

views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in transform.

Returns:

self – The updated object.

Return type:

object

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