-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX check that parameters validation happen in fit for KernelPCA #21567
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this changes the behavior of the estimator, it would require an entry in the changelog.
It's under doc/whats_new/v1.1.rst
sklearn/decomposition/_kernel_pca.py
Outdated
if self.fit_inverse_transform and self.kernel == "precomputed": | ||
raise ValueError("Cannot fit_inverse_transform with a precomputed kernel.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this validation to the beginning of the fit
method, so that it's done before _validate_data
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also make sure this is tested in the test file.
Specifically, you need to change the test def test_kernel_pca_invalid_parameters():
"""Check that kPCA raises an error if the parameters are invalid
Tests fitting inverse transform with a precomputed kernel raises a
ValueError.
"""
with pytest.raises(ValueError):
estimator = KernelPCA(n_components=10, fit_inverse_transform=True, kernel="precomputed")
estimator.fit(np.random.randn(10, 10)) |
827f795
to
68a2e76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MaggieChege
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution, @MaggieChege.
Some tiny changes can be introduced and this LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution, @MaggieChege.
…kit-learn#21567) Co-authored-by: ciku <maggie@hellotractor.com>
…kit-learn#21567) Co-authored-by: ciku <maggie@hellotractor.com>
…kit-learn#21567) Co-authored-by: ciku <maggie@hellotractor.com>
Reference Issues/PRs
Addresses #21406
What does this implement/fix? Explain your changes.
Fix validate parameters in fit for KernelPCA
Any other comments?
#DataUmbrella