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

Skip to content

Conversation

@venkyyuvy
Copy link
Contributor

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
Copy link
Member

@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

can you add a whatsnew?

@amueller
Copy link
Member

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

@amueller amueller dismissed their stale review August 22, 2019 17:53

I was wrooong!

@venkyyuvy
Copy link
Contributor Author

can you add a whatsnew?

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

@glemaitre
Copy link
Member

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

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

ya, makes sense. Thanks for the input.

Co-Authored-By: Tom DuprΓ© la Tour <[email protected]>
Co-Authored-By: Tom DuprΓ© la Tour <[email protected]>
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.

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

@venkyyuvy
Copy link
Contributor Author

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

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.

LGTM, thanks @venkyyuvy

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

TomDLT commented Aug 28, 2019

Nice, thanks !

@venkyyuvy venkyyuvy deleted the precomputed_kernel branch May 19, 2020 07:05
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.

kernel_approximation.Nystroem does not support precomputed kernel

5 participants