[MRG + 1] Fix repr on isotropic kernels when a 1-D length scale is given#7259
Merged
jnothman merged 4 commits intoscikit-learn:masterfrom Sep 3, 2016
Merged
[MRG + 1] Fix repr on isotropic kernels when a 1-D length scale is given#7259jnothman merged 4 commits intoscikit-learn:masterfrom
jnothman merged 4 commits intoscikit-learn:masterfrom
Conversation
Member
|
Shouldn't we test all |
sklearn/gaussian_process/kernels.py
Outdated
| else: | ||
| return "{0}(length_scale={1:.3g}, nu={2:.3g})".format( | ||
| self.__class__.__name__, self.length_scale, self.nu) | ||
| self.__class__.__name__, _squeeze(self.length_scale), self.nu) |
Member
Author
There was a problem hiding this comment.
I reimplemented np.squeeze because .format does not play well with a 0-D array.
a = "{0:0.3g}".format(np.array(2))
TypeError: non-empty format string passed to object.__format__
a = "%0.3g" % np.array(2)
a
'2'Probably should be reported to NumPy...
Member
There was a problem hiding this comment.
np.ravel(length_scale)[0] or np.atleast_1d(length_scale)[0] should also work. I think the helper function is a bit obscure to the reader.
Member
Author
|
For now, I've just added a smoke test. Is that sufficient or should we test if stuff like "length_scale" is there in the string returned by repr? Also ping @jnothman |
Member
|
lgtm |
Member
|
I prefer |
Member
|
Thanks |
TomDLT
pushed a commit
to TomDLT/scikit-learn
that referenced
this pull request
Oct 3, 2016
paulha
pushed a commit
to paulha/scikit-learn
that referenced
this pull request
Aug 19, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix? Explain your changes.
Moving setting the
length_scalelogic from the constructor to the methods broke__repr__on a 1-D length_scale isotropic kernel.This was because the formatting expected
self.length_scaleto be a scalar while theself.length_scaleto be an array. To fix this, I squeeze the 1-D length_scale by squeezing it when__repr__is called.