8000 FIX check that parameters validation happen in fit for KernelPCA by MaggieChege · Pull Request #21567 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 4 commits into from
Nov 15, 2021

Conversation

MaggieChege
Copy link
Contributor

Reference Issues/PRs

Addresses #21406

What does this implement/fix? Explain your changes.

Fix validate parameters in fit for KernelPCA

Any other comments?

#DataUmbrella

Copy link
Member
@adrinjalali adrinjalali left a 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

Comment on lines 435 to 436
if self.fit_inverse_transform and self.kernel == "precomputed":
raise ValueError("Cannot fit_inverse_transform with a precomputed kernel.")
Copy link
Member

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.

Copy link
Member

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.

@glemaitre glemaitre changed the title fix validate parameters in fit for KernelPCA FIX check that parameters validation happen in fit for KernelPCA Nov 7, 2021
@glemaitre
Copy link
Member
glemaitre commented Nov 7, 2021

Specifically, you need to change the test test_kernel_pca_invalid_parameters by calling fit:

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))

Copy link
Member
@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Thanks @MaggieChege

Copy link
Member
@jjerphan jjerphan left a 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.

Copy link
Member
@jjerphan jjerphan left a 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.

@jjerphan jjerphan merged commit 87c330d into scikit-learn:main Nov 15, 2021
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Nov 22, 2021
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Nov 29, 2021
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
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.

5 participants
0