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

Venkatachalam N added 4 commits Aug 21, 2019
Venkatachalam N
Venkatachalam N
Venkatachalam N
Venkatachalam N
@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 left a comment

LGTM

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

Copy link
Member

amueller left a comment

can you add a whatsnew?

@amueller

This comment has been minimized.

Copy link
Member

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!

Venkatachalam N
@venkyyuvy

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

amueller commented Aug 24, 2019

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

Venkatachalam N
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 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
@venkyyuvy

This comment has been minimized.

Copy link
Contributor Author

venkyyuvy commented Aug 28, 2019

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

Copy link
Member

adrinjalali left a comment

LGTM, thanks @venkyyuvy

@TomDLT TomDLT merged commit e55e37c into scikit-learn:master Aug 28, 2019
18 checks passed
18 checks passed
LGTM analysis: C/C++ No code changes detected
Details
LGTM analysis: JavaScript No code changes detected
Details
LGTM analysis: Python No new or fixed alerts
Details
ci/circleci: deploy Your tests passed on CircleCI!
Details
ci/circleci: doc Your tests passed on CircleCI!
Details
ci/circleci: doc artifact Link to 0/doc/_changed.html
Details
ci/circleci: doc-min-dependencies Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 96.9%)
Details
codecov/project 96.91% (+<.01%) compared to 2812bb1
Details
scikit-learn.scikit-learn Build #20190828.4 succeeded
Details
scikit-learn.scikit-learn (Linux py35_conda_openblas) Linux py35_conda_openblas succeeded
Details
scikit-learn.scikit-learn (Linux py35_ubuntu_atlas) Linux py35_ubuntu_atlas succeeded
Details
scikit-learn.scikit-learn (Linux pylatest_conda_mkl_pandas) Linux pylatest_conda_mkl_pandas succeeded
Details
scikit-learn.scikit-learn (Linux32 py35_ubuntu_atlas_32bit) Linux32 py35_ubuntu_atlas_32bit succeeded
Details
scikit-learn.scikit-learn (Windows py35_pip_openblas_32bit) Windows py35_pip_openblas_32bit succeeded
Details
scikit-learn.scikit-learn (Windows py37_conda_mkl) Windows py37_conda_mkl succeeded
Details
scikit-learn.scikit-learn (macOS pylatest_conda_mkl) macOS pylatest_conda_mkl succeeded
Details
@TomDLT

This comment has been minimized.

Copy link
Member

TomDLT commented Aug 28, 2019

Nice, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.