Skip to content

PR addressing https://github.com/scikit-learn/scikit-learn/issues/5229#5316

Closed
carrillo wants to merge 8 commits intoscikit-learn:masterfrom
carrillo:master
Closed

PR addressing https://github.com/scikit-learn/scikit-learn/issues/5229#5316
carrillo wants to merge 8 commits intoscikit-learn:masterfrom
carrillo:master

Conversation

@carrillo
Copy link
Copy Markdown
Contributor

  1. Generated a class variable: KERNEL_DEFAULT_PARAMS dictionary of kernel default parameters. I removed "exp_chi2" kernel from the dictionary as discussed in added missing chi2 gamma parameter #5211. The current "chi2" kernel is missing the gamma parameter. This has to be changed in sklearn/metrics/pairwise.py (see added missing chi2 gamma parameter #5211) in order to work. Let me know if I should do that.
  2. Modified init(): Set default values for kernel parameters to Null (default parameters will be obtained from dictionary)
  3. Modified get_kernel_parameters(): if self.kernel is not callable, it checks
    if the kernel is contained in the dictionary. If so, it assigns the default parameters contained KERNEL_DEFAULT_PARAMS if not specified in__init
    _()

…in Nystroem

1. Generated a class variable: KERNEL_DEFAULT_PARAMS dictionary of kernel default parameters.
2. Modified __init__(): Set default values for kernel to Null
3. Modified _get_kernel_parameters(): if the self.kernel parameter is not callable, it checks
if the kernel is contained in the dictionary. For each kernel parameter defined in the dictionary it
assigns the default if None specified in __init__() or the one specified.
@TomDLT
Copy link
Copy Markdown
Member

TomDLT commented Sep 29, 2015

I think you can uncomment "chi2": [{"gamma": 1.}],.
Your dictionary is somehow the same as here. Could you use only one dictionary?

@carrillo
Copy link
Copy Markdown
Contributor Author

Dear Tom, thanks for you comments.
You are absolutely right, I can uncomment "chi2": [{"gamma": 1.}]. I will do so.
The dictionary you are referring to has no default parameters, only parameter names. Do you think there should be one global dictionary with kernel names, parameter names and default values?

@TomDLT
Copy link
Copy Markdown
Member

TomDLT commented Sep 29, 2015

You could reuse your dictionary (with default values) where the old one (without default values) was used (here).

>>>"gamma" in frozenset(["gamma", "degree", "coef0"])
True
>>>"gamma" in {"gamma": None, "degree": 3, "coef0": 1}
True

…ameters.

Removed KERNEL_DEFAULT_PARAMS in kernel_approximation.py
@carrillo
Copy link
Copy Markdown
Contributor Author

Sorry for the delay. I just implemented the changes: I added the default kernel parameters to the dictionary in pairwise.py, removed the dictionary in kernel_approximation.py and import the one in pairwise.py.

@TomDLT
Copy link
Copy Markdown
Member

TomDLT commented Oct 1, 2015

This looks good to me.
Could you also add a small non-regression test?
Is it what you had in mind @amueller ?

@carrillo
Copy link
Copy Markdown
Contributor Author

carrillo commented Oct 1, 2015

Should the test address anything else then calling the Nystroem approximation without specifying the gamma parameter for the rbf and chi^2 kernel (this is where Travis was failing).
Should I add the test to sklearn.tests.test_kernel_approximation.py?

@carrillo
Copy link
Copy Markdown
Contributor Author

carrillo commented Oct 6, 2015

I have the feeling that the non-regression test is already covered here. Lines 164 - 169 call the kernels with default parameters:

# test that available kernels fit and transform
kernels_available = kernel_metrics()
for kern in kernels_available:
    trans = Nystroem(n_components=2, kernel=kern, random_state=rnd)
    X_transformed = trans.fit(X).transform(X)
    assert_equal(X_transformed.shape, (X.shape[0], 2))

This test failed, because it called the chi2 kernel with the default gamma value for the rbf kernel (gamma:None). Now the default gamma for chi2 (1.) is taken from the dictionary.

Please let me know if I should add another test.

Thanks,

Fernando

@amueller
Copy link
Copy Markdown
Member

Not entirely the change I had in mind, and KERNEL_PARAMS is public, right? So maybe we shouldn't change it?
A good test would be to run RBFSampler with different chi2 and different gamma and see that the results actually change (in the same way as when rescaling the data). That wasn't the case before, right?

The fix I suggested was passing a dict of arguments in the RBFSampler.__init__ and deprecating the other parameters.
You just introduced "another" place where defaults are kept and they need to be in sync with the defaults elsewhere. We could add tests that ensure consistency but I feel this is asking for trouble.

@amueller
Copy link
Copy Markdown
Member

[sorry for prolonged absence]

@rth
Copy link
Copy Markdown
Member

rth commented Apr 21, 2018

Closing as the original issue #5229 was resolved in #9166

@rth rth closed this Apr 21, 2018
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.

4 participants