Thanks to visit codestin.com
Credit goes to github.com

Skip to content

incorrect PLS rank bounds #29662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adrinjalali opened this issue Aug 13, 2024 · 0 comments · Fixed by #29710
Closed

incorrect PLS rank bounds #29662

adrinjalali opened this issue Aug 13, 2024 · 0 comments · Fixed by #29710

Comments

@adrinjalali
Copy link
Member

From #26204 (review)

Going through the math, I think the code is incorrect. The rank of X.T @ X is bounded above by min(n_samples, n_features) and not just n_features. We can update the implementation to reflect this:

diff --git a/sklearn/cross_decomposition/_pls.py b/sklearn/cross_decomposition/_pls.py
index dce2c23db2..4346905f00 100644
--- a/sklearn/cross_decomposition/_pls.py
+++ b/sklearn/cross_decomposition/_pls.py
@@ -246,7 +246,9 @@ class _PLS(
         # With PLSRegression n_components is bounded by the rank of (X.T X) see
         # Wegelin page 25. With CCA and PLSCanonical, n_components is bounded
         # by the rank of X and the rank of Y: see Wegelin page 12
-        rank_upper_bound = p if self.deflation_mode == "regression" else min(n, p, q)
+        rank_upper_bound = (
+            min(n, p) if self.deflation_mode == "regression" else min(n, p, q)
+        )
         if n_components > rank_upper_bound:
             raise ValueError(
                 f"`n_components` upper bound is {rank_upper_bound}. "

I would treat this as a bug fix because it makes the implementation consistent with the paper.

For reference, here is a quick example of the rank being bounded by n_samples:

import numpy as np

rng = np.random.RandomState(42)
X = rng.standard_normal(size=(20, 54))

print(np.linalg.matrix_rank(X.T @ X))
# 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants