Skip to content
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

[MRG] FIX Nystroem with precomputed kernel #14706

Merged
merged 11 commits into from Aug 28, 2019

Conversation

venkyyuvy
Copy link
Contributor

@venkyyuvy venkyyuvy commented Aug 21, 2019

Reference Issues/PRs

Fixes #14641

What does this implement/fix? Explain your changes.

Added

  • key precomputed in KERNEL_PARAMS
  • non-regression test to validate Nystroem with precomputed kernel using polynomial_kernel

Any other comments?

@venkyyuvy venkyyuvy changed the title key_precomputed [MRG] key_precomputed Aug 22, 2019
@TomDLT TomDLT changed the title [MRG] key_precomputed [MRG] FIX Nystroem with precomputed kernel Aug 22, 2019
TomDLT
TomDLT approved these changes Aug 22, 2019
Copy link
Member

@TomDLT TomDLT left a comment

LGTM

Please also add a bugfix entry in doc/whats_new/0.22.rst.

amueller
amueller previously approved these changes Aug 22, 2019
Copy link
Member

@amueller amueller left a comment

can you add a whatsnew?

@amueller
Copy link
Member

@amueller amueller commented Aug 22, 2019

actually, not sure if this is the right fix, maybe _get_kernel_params in Nystroem should be fixed.

@amueller amueller dismissed their stale review Aug 22, 2019

I was wrooong!

@venkyyuvy
Copy link
Contributor Author

@venkyyuvy venkyyuvy commented Aug 23, 2019

can you add a whatsnew?

Now we can use the Nystroem with precomputed kernel matrix. Previous it was giving KeyError: 'precomputed'

@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Aug 23, 2019

actually, not sure if this is the right fix, maybe _get_kernel_params in Nystroem should be fixed.

@amueller
Do you mean that it makes more sense for _get_kernel_params() to return an empty tuple instead of registering 'precomputed' as a kernel? Is it because 'precomputed' kernel would not be a kernel?

        if self.kernel == 'precomputed':
            return params
        if not callable(self.kernel):
            for param in (KERNEL_PARAMS[self.kernel]):
                if getattr(self, param) is not None:
                    params[param] = getattr(self, param)
        else:
            if (self.gamma is not None or
                    self.coef0 is not None or
                    self.degree is not None):
                raise ValueError("Don't pass gamma, coef0 or degree to "
                                 "Nystroem if using a callable kernel.")

@TomDLT
Copy link
Member

@TomDLT TomDLT commented Aug 23, 2019

Right, if someone wants to iterate over KERNEL_PARAMS' keys, "precomputed" does not make sense. Then your fix would be better.

@venkyyuvy
Copy link
Contributor Author

@venkyyuvy venkyyuvy commented Aug 24, 2019

Do you mean that it makes more sense for _get_kernel_params() to return an empty tuple instead of registering 'precomputed' as a kernel? Is it because 'precomputed' kernel would not be a kernel?

@glemaitre

Please correct me If I am wrong,
Aren't we supposed to check, whether

(self.gamma is not None or
   self.coef0 is not None or
   self.degree is not None)

when kernel='precomputed' then raise a ValueError

"Don't pass gamma, coef0 or degree to Nystroem if using precomputed kernel."

On a side note, I saw here, we have been using this inside PAIRWISE_DISTANCE_FUNCTIONS .

        'precomputed': None,  # HACK: precomputed is always allowed, never called

That is the reason, why I had pursued ahead to add precomputed in KERNEL_PARAMS

@amueller
Copy link
Member

@amueller amueller commented Aug 24, 2019

I feel if we can avoid the hack that's better ;)

sklearn/kernel_approximation.py Outdated Show resolved Hide resolved
ya, makes sense. Thanks for the input.

Co-Authored-By: Tom Dupré la Tour <tom.dupre-la-tour@m4x.org>
sklearn/kernel_approximation.py Outdated Show resolved Hide resolved
Co-Authored-By: Tom Dupré la Tour <tom.dupre-la-tour@m4x.org>
Copy link
Member

@adrinjalali adrinjalali left a comment

Please also test that the correct error is raised with a precomputed kernel and passed kernel parameters.

doc/whats_new/v0.22.rst Outdated Show resolved Hide resolved
doc/whats_new/v0.22.rst Outdated Show resolved Hide resolved
doc/whats_new/v0.22.rst Outdated Show resolved Hide resolved
sklearn/tests/test_kernel_approximation.py Show resolved Hide resolved
@venkyyuvy
Copy link
Contributor Author

@venkyyuvy venkyyuvy commented Aug 28, 2019

Thanks a lot @adrinjalali for your valuable comments. Please review my latest commit.

Copy link
Member

@adrinjalali adrinjalali left a comment

LGTM, thanks @venkyyuvy

@TomDLT TomDLT merged commit e55e37c into scikit-learn:master Aug 28, 2019
18 checks passed
@TomDLT
Copy link
Member

@TomDLT TomDLT commented Aug 28, 2019

Nice, thanks !

@venkyyuvy venkyyuvy deleted the precomputed_kernel branch May 19, 2020
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 this pull request may close these issues.

5 participants