Skip to content

DOC Add numerical stability note to CCA when n_features > n_samples - #33791

Open
RudrenduPaul wants to merge 1 commit into
scikit-learn:mainfrom
RudrenduPaul:DOC-cca-numerical-stability-note
Open

RudrenduPaul wants to merge 1 commit into
scikit-learn:mainfrom
RudrenduPaul:DOC-cca-numerical-stability-note

Conversation

@RudrenduPaul

@RudrenduPaul RudrenduPaul commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #19042

What does this implement/fix? Explain your changes.

CCA (Canonical Correlation Analysis, mode B) uses pseudo-inverse computations internally. These become numerically unstable when n_features > n_samples or n_targets > n_samples — the fitted weights may depend on the order of columns in X or y and cannot be interpreted reliably.

This instability was already documented as a code comment at line 73–74 of _pls.py:

# As a result, and as detailed in the Wegelin's review, CCA (i.e. mode
# B) will be unstable if n_features > n_samples or n_targets > n_samples

But it was absent from the public docstring, so users calling CCA directly had no way to discover this limitation without reading the source.

This PR adds a Notes section to the CCA class docstring documenting:

  • The instability condition
  • The recommendation to use PLSCanonical as an alternative
  • A reference to the Wegelin review already cited in the source code

Did you add any tests? Why or why not?

No — this is a documentation-only change (a Notes section added to a docstring). No behavior changes.


AI Assistance Disclosure (required per AGENTS.md)
This pull request includes code written with the assistance of AI (Claude Code).
All changes have been read, understood, and verified by the human contributor (Rudrendu Paul).

CCA (mode B) uses pseudo-inverse computations which become numerically
unstable when n_features > n_samples or n_targets > n_samples — the
fitted weights may depend on column order and should not be interpreted.
This note was already present as a code comment (line 73-74) but was
missing from the public docstring visible to users.

Adds a Notes section to the CCA class docstring documenting the
instability condition and suggesting PLSCanonical as an alternative,
with a reference to the Wegelin review already cited in the source.

Fixes scikit-learn#19042

Built by Rudrendu Paul, developed with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CCA axes depend on the order of columns in Y matrix

1 participant