cca_zoo.tree¶
Gradient-boosted-tree nonlinear CCA methods. Requires pip install cca-zoo[tree].
TreeCCA ¶
TreeCCA(
latent_dimensions: int = 1,
center: bool = True,
backend: str = "xgboost",
n_estimators: int = 50,
max_depth: int = 5,
learning_rate: float = 0.1,
subsample: float = 0.8,
colsample_bytree: float = 0.8,
min_child_weight: float = 5,
gauss_seidel: bool = True,
random_state: int = 0,
)
Bases: BaseModel
TreeCCA — nonlinear multiview CCA with gradient-boosted-tree encoders.
Learns one nonlinear encoder \(f_i\) per view (a gradient-boosted tree ensemble per latent dimension) that jointly maximise the Eckart-Young (EY) unconstrained-CCA objective:
where, for embeddings \(Z_i = f_i(X_i)\), \(C\) is the mean
pairwise cross-covariance (including \(i = j\) terms) and \(V\)
the mean auto-covariance across all views (see
:mod:cca_zoo._utils._ey, the same shared EY-loss machinery used by
:class:~cca_zoo.linear.gradient.CCA_EY and
:class:~cca_zoo.deep.DCCA_EY). The encoders are fit by alternating
(Gauss-Seidel) gradient boosting: each round, for every view in turn, one
tree is added to each of its latent_dimensions boosters using the
EY-loss gradient (rescaled to a fixed target standard deviation for
well-conditioned tree leaves) as a custom regression objective, and —
when gauss_seidel=True — the gradient is recomputed from the
freshest embeddings before moving to the next view. Training starts from
a random-orthogonal, unit-variance initial embedding per view. Because
each latent component is a boosted-tree ensemble, per-component feature
importance (split gain) is available directly, without a separate
interpretability method such as SHAP.
This is a from-scratch reimplementation, as a scikit-learn-style
:class:~cca_zoo._base.BaseModel, of the "Design A" (sequential,
scalar-booster) training procedure from the TreeCCA research codebase,
generalised from two views to an arbitrary number of views.
References
Chapman, J. (2026). TreeCCA: Canonical Correlation Analysis via Gradient-Boosted Trees. arXiv:2607.27027.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimensions
|
int
|
Number of latent components. Must not exceed the number of features in any view. Default is 1. |
1
|
center
|
bool
|
Whether to subtract per-view column means before fitting. Default is True. |
True
|
backend
|
str
|
Gradient-boosting library used for the per-component
encoders: |
'xgboost'
|
n_estimators
|
int
|
Number of boosting rounds (trees added per booster). Default is 50. |
50
|
max_depth
|
int
|
Maximum depth of each tree. Default is 5. |
5
|
learning_rate
|
float
|
Boosting learning rate. Default is 0.1. |
0.1
|
subsample
|
float
|
Row subsampling ratio per tree. Default is 0.8. |
0.8
|
colsample_bytree
|
float
|
Column subsampling ratio per tree. Default is 0.8. |
0.8
|
min_child_weight
|
float
|
Minimum sum of instance weight (xgboost) / minimum number of samples (lightgbm) needed in a child. Default is 5. |
5
|
gauss_seidel
|
bool
|
If True, re-predict view 1's embedding after updating its boosters and use the fresh values when computing view 2's gradient (Gauss-Seidel); if False, both gradients are computed from the same stale embeddings (Jacobi). Default is True. |
True
|
random_state
|
int
|
Seed for the boosters and for drawing the random-orthogonal initial embedding. Default is 0. |
0
|
Example
import numpy as np rng = np.random.default_rng(0) X1 = rng.standard_normal((100, 5)) X2 = rng.standard_normal((100, 5)) model = TreeCCA(latent_dimensions=2, n_estimators=10).fit([X1, X2]) scores = model.transform([X1, X2])
Source code in cca_zoo/tree/_treecca.py
weights
property
¶
Not implemented for TreeCCA.
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If |
NotImplementedError
|
TreeCCA encoders are boosted-tree ensembles,
not linear weight matrices. Use |
fit ¶
Fit the TreeCCA model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of 2 or more arrays, each (n_samples, n_features_i). |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
TreeCCA
|
Fitted estimator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 views are provided. |
ValueError
|
If views have inconsistent numbers of samples. |
ValueError
|
If |
ImportError
|
If |
Source code in cca_zoo/tree/_treecca.py
transform ¶
Project views into the latent space using the fitted boosters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
list[ArrayLike]
|
List of arrays, each (n_samples, n_features_i), matching
the number of views passed to |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
List of arrays, each (n_samples, latent_dimensions). |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If |
ValueError
|
If fewer than 2 views are provided. |