Foundations to Frontier
Tests
D. Classical Machine Learning › D9 Dimensionality Reduction and Manifold Learning

Canonical Correlation Analysis (CCA)

Canonical correlation analysis (Hotelling, 1936) finds pairs of linear combinations, one from each of two sets of variables, that are maximally correlated with each other. It is the natural tool when two views measure the same underlying phenomenon, such as two sensor suites, images and text, or inputs and outputs. The canonical correlations are the singular values of the whitened cross-covariance Σxx^(−½) Σxy Σyy^(−½), and the canonical variates are uncorrelated within each view. CCA is invariant to invertible linear transformations of either view, which makes it scale-free but also prone to severe overfitting when the number of variables is not small compared with the sample size; regularised (ridge) CCA is the standard fix. This page covers the formulation, the SVD solution, invariance, the relation to regression and LDA, significance and overfitting, regularisation, and kernel and deep extensions. In the exercises you implement CCA and recover shared latent signals; then you measure how plain and regularised CCA behave as the sample size shrinks.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

What do two sets of measurements have in common?

Suppose an aircraft carries two independent sensor suites, or you have both images and maintenance notes for each part. CCA looks for a combination of the first set’s variables and a combination of the second set’s that move together as closely as possible. It then finds a second pair, unrelated to the first, and so on. Each pair reveals a shared signal behind the two views, along with how strongly they agree on it.

CCA: correlated directions across two views, and how they overfit
training datafresh data
first canonical correlation: training 0.981 · fresh data 0.106 · truth 0.600
Each view has 10 variables. With n near 20 (the total number of variables), plain CCA can find directions whose training correlation is nearly 1 even though the fresh-data correlation is near 0: it fits noise. Raise λ to shrink the covariance estimates and the training correlation falls while the fresh-data correlation rises. With hundreds of samples, plain CCA settles near the true 0.6 on both, and regularisation now costs a little (it biases the directions).
Why engineers care

Cross-checking redundant sensor suites, finding which input variables drive which outputs, fusing multimodal data, and calibrating one instrument against another are all “two views of one system” problems. CCA quantifies the shared structure, and its regularised, kernel and deep variants underlie modern multiview learning.

📝 Quick check (Level 0)
0/3 answered
  1. 1. CCA relates…
  2. 2. The first canonical pair is chosen to be…
  3. 3. With few samples and many variables, CCA's training correlation is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Canonical correlations by hand

One variable per view. CCA reduces to the absolute Pearson correlation.

A shared latent signal. If x = z + e₁ and y = z + e₂, with unit-variance z and independent noises of variances σ₁² and σ₂²:

corr(x, y) = 1/√((1 + σ₁²)(1 + σ₂²)).

  • Noise variances 0.25 and 0.25 give 0.8.
  • 1 and 1 give 0.5.
  • 0.25 and 1 give 0.632.

Whitening. Σ^(−½) for diag(4, 9) is diag(0.5, 1/3). After whitening each view, the canonical correlations are the singular values of the whitened cross-covariance.

Number of pairs. At most min(p, q). With few samples, also at most n − 1 non-trivial ones. For p = q = 20 and n = 10: 9.

The steps in plain English:

  1. Centre both views and compute Σxx, Σyy and Σxy, adding a ridge to Σxx and Σyy if n is not much larger than p + q.
  2. Form M = Σxx^(−½) Σxy Σyy^(−½) and take its SVD, M = U S Vᵀ.
  3. Canonical correlations are the diagonal of S. The directions are a = Σxx^(−½) uᵢ and b = Σyy^(−½) vᵢ.
  4. Report canonical variates Xa and Yb, check correlations on held-out data, and interpret the loadings (correlations of the original variables with the variates).
📝 Quick check (Level 1)
0/3 answered
  1. 1. corr(z + e₁, z + e₂) with noise variances 3 and 0?
  2. 2. Maximum canonical pairs for p = 3, q = 5, n = 100?
  3. 3. CCA with one variable per view gives…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Why the SVD, invariance, and overfitting

Derivation. Maximise corr(Xa, Yb) = aᵀΣxy b / √(aᵀΣxx a · bᵀΣyy b). Substituting ã = Σxx^½a and b̃ = Σyy^½b, this becomes ãᵀMb̃ / (‖ã‖‖b̃‖), which the top singular pair of M maximises. Later pairs are the next singular pairs. They are automatically uncorrelated with earlier variates within each view, and across views except for their own partner.

Invariance. Replacing X by XA for any invertible A leaves the canonical correlations unchanged. Exercise 1 mixed each view with an arbitrary linear map, and CCA still recovered the theoretical correlations: 0.793 and 0.502 against 0.8 and 0.5, and 0.007 for the third, which should be 0.

That invariance is a double-edged sword. CCA will happily amplify any direction, however noisy, if it raises the correlation.

Overfitting. With n ≤ p + q, there are directions giving perfect training correlation, even for independent views. In exercise 2 (two 20-D views, true canonical correlation 0.6):

  • with n = 30, plain CCA reported 1.000 on the training data and only 0.02–0.03 on fresh data;
  • ridge regularisation (λ = 0.5) lowered the training value to 0.74 and raised the fresh-data value to 0.17;
  • only by n of about 2000 did training and fresh-data correlation agree at 0.6.

Regularised CCA. Use Σxx + λ(tr Σxx/p)I, and likewise for Σyy. As λ → ∞, CCA approaches PLS-SVD, which maximises covariance instead of correlation. Choose λ by cross-validating the held-out canonical correlation.

Relations.

  • If Y is one-hot class labels, CCA’s X-directions are Fisher’s LDA directions.
  • With one-dimensional Y, the first canonical correlation is the multiple correlation R from regressing Y on X.
  • Kernel CCA and deep CCA find nonlinear shared structure, and need even stronger regularisation.
from sklearn.cross_decomposition import CCA
cca = CCA(n_components=2).fit(X_train, Y_train)          # (unregularised)
U, V = cca.transform(X_test, Y_test)                     # check correlations on held-out data!
🐍 Exercise 1: CCA by whitening and SVD
Implement (optionally ridge-regularised) inverse square roots and CCA via the SVD of the whitened cross-covariance; recover two shared latent signals hidden in arbitrarily mixed views.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Canonical correlations are the singular values of…
  2. 2. With n ≤ p + q, plain CCA can reach a training correlation of…
  3. 3. As the ridge λ → ∞, CCA approaches…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Sampling distribution. Under independence (true correlation 0), the largest sample canonical correlation is large when p and q are comparable to n, following Wachter or Jacobi-ensemble limits. Classic tests:

  • Bartlett’s χ² approximation for the number of significant pairs, −(n − 1 − (p + q + 1)/2) Σ log(1 − ρᵢ²);
  • Wilks’ Λ.

Both are reliable only when n is large relative to p + q. Otherwise use permutation tests: shuffle one view’s rows.

Probabilistic CCA. Bach and Jordan (2005) showed that CCA is the maximum-likelihood solution of a latent-variable model with a shared Gaussian latent and view-specific noise. That is the two-view analogue of probabilistic PCA, and it allows priors, missing data and Bayesian versions.

Interview questions.

  • How would you test whether two sensor suites share information? Use regularised CCA on training data, evaluate the canonical correlations on held-out data or by permutation, and report the loadings for the significant pairs.
  • CCA, PLS or regression? Regression to predict one view from the other. CCA for symmetric shared structure, correlation-based and scale-free. PLS when you want covariance-weighted directions that are more stable with many correlated variables.
📝 Quick check (Level 3)
0/3 answered
  1. 1. A robust way to test canonical correlations when n is small is…
  2. 2. Probabilistic CCA posits…
  3. 3. If Y is one-hot class labels, CCA's X-directions match…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

How badly does CCA overfit?

History.

  • H. Hotelling introduced canonical correlations (1936).
  • M. Bartlett (1941) gave significance tests.
  • H. Vinod (1976) proposed ridge (canonical ridge) regularisation.
  • F. Bach and M. Jordan (2002, 2005) developed kernel CCA and probabilistic CCA.
  • G. Andrew et al. (2013) introduced deep CCA.

Exercise 2. Two 20-D views sharing one latent signal (true first canonical correlation 0.6), 4 datasets. Each cell shows the first canonical correlation on the training data, then on 3000 fresh samples.

n plain (λ = 0) λ = 0.1 λ = 0.5
30 1.000, 0.029† 0.926, 0.126 0.741, 0.167
60 0.941, 0.093 0.853, 0.216 0.669, 0.321
120 0.768, 0.380 0.712, 0.429 0.563, 0.467
480 0.652, 0.551 0.611, 0.556 0.491, 0.564
2000 0.606, 0.597 0.570, 0.597 0.460, 0.599

† At n = 30 plain CCA inverts a singular covariance, so this value depends on rounding: the in-browser Python gives 0.016.

  • With fewer samples than variables (30 < 40), plain CCA reported perfect correlation that did not exist on new data.
  • Regularisation always improved the fresh-data correlation when n was small, at the cost of a lower (biased) training value. Never trust a training canonical correlation without held-out checks.
  • Even at n = 480 (12 samples per variable), the training value overstated the truth (0.65 against a held-out 0.55).
🐍 Exercise 2 (research): overfitting and regularisation
For two 20-D views sharing one signal (true correlation 0.6), compute the first canonical correlation on training and fresh data for n from 30 to 2000 with ridge λ = 0, 0.1, 0.5.

CCA in AI, robotics and aerospace

  • Redundant-sensor consistency: canonical correlations between two independent suites drop when one degrades.
  • Multimodal fusion: aligning camera and lidar features, or images and text, in a shared space (deep CCA).
  • Input–output analysis: finding which control-input combinations drive which response combinations.

References

  1. H. Hotelling (1936). “Relations between two sets of variates.” Biometrika 28(3/4).
  2. F. R. Bach, M. I. Jordan (2005). “A probabilistic interpretation of canonical correlation analysis.” Technical report 688, UC Berkeley.
  3. D. R. Hardoon, S. Szedmak, J. Shawe-Taylor (2004). “Canonical correlation analysis: an overview with application to learning methods.” Neural Computation 16(12).
  4. G. Andrew, R. Arora, J. Bilmes, K. Livescu (2013). “Deep canonical correlation analysis.” Proc. ICML.
  5. H. D. Vinod (1976). “Canonical ridge and econometrics of joint production.” Journal of Econometrics 4(2).