-
-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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] add _pairwise property to BaseSearchCV #13925
[MRG] add _pairwise property to BaseSearchCV #13925
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe what I really want here is a non-regression test for the example posted in the original issue.
setattr(est, '_pairwise', _pairwise_setting) | ||
cv = PairwiseCV(est) | ||
|
||
# check if cv is pairwise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is redundant with the variable name
cv = PairwiseCV(est) | ||
|
||
# check if cv is pairwise | ||
cv_is_pairwise = getattr(cv, '_pairwise', False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use cv._pairwise
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the convention of safe_split
but hit the 80 character limit so I broke it into a separate line. I suppose since checking cv._pairwise
won't throw an error for not being instantiated, we can just use it here. I'll make the swap
I made your suggested edits and added a classification test similar to #13920 with We could get rid of the old test case I'd written, but the original is a bit broader in scope as it uses BaseSearchCV for any custom CV object instead of just using GridSearchCV. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an entry to the change log at doc/whats_new/v0.22.rst
. Like the other entries there, please reference this pull request with :pr:
and credit yourself (and other contributors if applicable) with :user:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few comments but looks good
:mod:`sklearn.model_selection` | ||
.................. | ||
|
||
- |Fix| :class:`model_selection.BaseSearchCV` now supports the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to GridSearchCV and RandomizedSearchCV instead.
Test implementation of BaseSearchCV has the _pairwise property | ||
which matches the _pairwise property of its estimator. | ||
""" | ||
class PairwiseCV(BaseSearchCV): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not using GridSearchCV instead of creating a dummy class?
def __init__(self, estimator, **kwargs): | ||
super().__init__(estimator, **kwargs) | ||
|
||
# first test: check BaseSearchCV children copy _pairwise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what that means.
what about:
Make sure _pairwise is delegated to the base estimator
No activity for several months, I'm picking this one up - will try to address the lingering comments. |
@jnothman, @NicolasHug, if I understand correctly this PR has been superseded by #15524, already merged. |
Thanks @cmarmo |
Fixes #13920
Previously BaseSearchCV did not support a 'precomputed' distance metric.
This PR simply adds a _pairwise property to the BaseSearchCV to ensure that some X evaluated with the 'precomputed' distance metric can be properly split during cross-validation by
_safe_split