Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FIX Fixes PLSRegression regression for constant Yk #19922

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

Merged
merged 7 commits into from
Apr 23, 2021

Conversation

thomasjpfan
Copy link
Member

Reference Issues/PRs

Fixes #19831

What does this implement/fix? Explain your changes.

Places the check on y from 0.23.2 back into the loop.

@@ -232,6 +232,11 @@ def fit(self, X, Y):
# paper.
Y_eps = np.finfo(Yk.dtype).eps
for k in range(n_components):
if np.all(np.dot(Yk.T, Yk) < Y_eps):
# Yk constant
warnings.warn('Y residual constant at iteration %s' % k)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮 no fstrings?

Suggested change
warnings.warn('Y residual constant at iteration %s' % k)
warnings.warn('Y residual is constant at iteration %s' % k)

@@ -232,6 +232,11 @@ def fit(self, X, Y):
# paper.
Y_eps = np.finfo(Yk.dtype).eps
for k in range(n_components):
if np.all(np.dot(Yk.T, Yk) < Y_eps):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we catch the StopIteration (in the nipals algorithm above) instead?

This is potentially a pretty expensive check to run (matrix multiplication), and I'm not sure at first sight that it's more accurate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that makes sense. I moved the logic to catching the exception and breaking out of the loop then.

@thomasjpfan thomasjpfan added this to the 0.24.2 milestone Apr 19, 2021
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @NicolasHug Could you have a second look such that we can include in 0.24.2

_get_first_singular_vectors_power_method(
Xk, Yk, mode=self.mode, max_iter=self.max_iter,
tol=self.tol, norm_y_weights=norm_y_weights)
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more thinking about doing the try/except on the offending line:

y_score = next(col for col in Y.T if np.any(np.abs(col) > eps))

Is there a way we can move it there while keeping the logic here reasonably sane?
My concern is that it's not obvious which line can raise a StopIteration if we leave the try/except here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we catch it at y_score, we still need to raise another exception to tell the caller to break out of the loop.

I added 3d4b6d2 (#19922) to make the control flow a little more obvious.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Thomas

@NicolasHug NicolasHug changed the title FIX Fixes PLSRegression regression for constant Y FIX Fixes PLSRegression regression for constant Yk Apr 23, 2021
@NicolasHug NicolasHug merged commit 2641baf into scikit-learn:main Apr 23, 2021
@glemaitre
Copy link
Member

I will backport it in the PR for the release now

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.

PLSRegression fails to fit some data with StopIteration
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.