cca_zoo.preprocessing¶
Per-view sklearn preprocessing adapters for multiview pipelines.
PerViewTransformer ¶
Bases: BaseEstimator
Apply an sklearn transformer to each view separately.
Fits a clone per view, taking and returning a list of views, so it
chains with multiview estimators in a :class:~sklearn.pipeline.Pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer
|
BaseEstimator | list[BaseEstimator]
|
A transformer, cloned per view, or one per view. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
transformers_ |
The fitted transformer of each view. |
Examples:
>>> import numpy as np
>>> from sklearn.decomposition import PCA
>>> from sklearn.pipeline import Pipeline
>>> from sklearn.preprocessing import StandardScaler
>>> from cca_zoo.linear import CCA
>>> from cca_zoo.preprocessing import PerViewTransformer
>>> rng = np.random.default_rng(0)
>>> X1, X2 = rng.standard_normal((50, 20)), rng.standard_normal((50, 15))
>>> pipe = Pipeline([
... ("scale", PerViewTransformer(StandardScaler())),
... ("pca", PerViewTransformer(PCA(n_components=5))),
... ("cca", CCA(n_components=2)),
... ])
>>> Z1, Z2 = pipe.fit_transform([X1, X2])
Source code in cca_zoo/preprocessing/_view_transformer.py
fit ¶
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
PerViewTransformer
|
self. |
Source code in cca_zoo/preprocessing/_view_transformer.py
transform ¶
Transform each view with its fitted transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
The transformed views. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are not as many views as in fit. |
Source code in cca_zoo/preprocessing/_view_transformer.py
fit_transform ¶
Fit, then transform the training views.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Arrays of shape (n_samples, n_features_i), one per view. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
The transformed views. |
Source code in cca_zoo/preprocessing/_view_transformer.py
inverse_transform ¶
Map transformed views back to their original feature spaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
Transformed views. |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
The views in their original feature spaces. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are not as many views as in fit. |
Source code in cca_zoo/preprocessing/_view_transformer.py
__sklearn_tags__ ¶
Tags marking list-of-views input, which sklearn's checks cannot validate.