-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG+1] MAINT Reuse unaltered classes/functions from model_selection #5568
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
Conversation
from .utils.metaestimators import if_delegate_has_method | ||
from .metrics.scorer import check_scoring | ||
from .exceptions import ChangedBehaviorWarning | ||
from .model_selection.search import ParameterGrid |
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.
Shouldn't need to specify .search
In general I approve of this cut-down on lines of code, and it also avoids people modifying the deprecated versions. There are test failures though. |
0f555b3
to
9c2b256
Compare
@jnothman all the tests should pass now! |
9c2b256
to
cb2e285
Compare
cb2e285
to
9b947e1
Compare
@jnothman :P |
9b947e1
to
da54321
Compare
hahaha 😆 |
da54321
to
8698152
Compare
8698152
to
2674ebc
Compare
2674ebc
to
c34f5e4
Compare
@@ -61,6 +62,16 @@ | |||
'train_test_split'] | |||
|
|||
|
|||
class FitFailedWarning(FitFailedWarning_): |
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 should be _FitFailedWarning
according to your tab completion explanation before....
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.
No this should be FitFailedWarning
so people can import this just like before, but with a deprecation warning of course.
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.
Oh, I meant FitFailedWarning_
-> _FitFailedWarning
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.
Ah that yes.
@MechCoder Thanks heaps for the review! |
c34f5e4
to
97d283f
Compare
Fixed both your comments! |
97d283f
to
a3de749
Compare
from abc import ABCMeta, abstractmethod | ||
|
||
import numpy as np | ||
import scipy.sparse as sp | ||
import sklearn.model_selection as mod_sel |
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.
You should use relative imports in modules (and absolute imports in tests), see http://scikit-learn.org/stable/developers/contributing.html#coding-guidelines.
You may as well move this import after the from scipy.misc import comb
. As far as I can see imports tend to be roughly ordered like this: stdlib, numpy, scipy, sklearn.
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.
Ah okay! Thanks...
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.
We also frown on "import as" for non standard imports: it makes reading the code harder because people need to scroll up to understand what the name of the module means.
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.
Thanks for the advice! (BTW if you can spare a few minutes, would you be able to review this? This has been around for a long time ;( )
121612c
to
9266ca4
Compare
9266ca4
to
7756278
Compare
I hope you meant to rename it to |
I thought @lesteve also gave a +1 |
@@ -25,6 +25,8 @@ | |||
with warnings.catch_warnings(): | |||
warnings.simplefilter('ignore') | |||
from sklearn import cross_validation as cval | |||
# We should be able to import this from cross_validation | |||
from sklearn.cross_validation import FitFailedWarning as _FFW |
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.
You are not using _FFW anywhere ...
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 is to test if FitFailedWarning
can be imported from our old path (which was public and needs to be supported for atleast 2 more versions)
from sklearn.cross_validation import FitFailedWarning as _
would be better in that case then.
@lesteve Apart from these comments, could I consider the review a +1 from your side? |
I woke from my nap, it seems. In hindsight not sure it was worth the effort, but there are indeed a lot of lines saved! Not able to look through this in detail right now, but tests seem to pass... |
Haha!! :D And this PR basically does 90% of what we do after the deprecations expire for One huge advantage is that when patching minor issues, we can do it once for the |
I don't have the necessary rights to change the PR title, so let's say it is a honorary +1 ;-).
I wholeheartedly agree on this one. |
TST Clean up the cross_validation and grid_search tests. ENH Use scipy's binomial coefficient function comb for calucation of nCk
02bcfab
to
d53d472
Compare
d53d472
to
982888f
Compare
if not np.all(hit): | ||
return False | ||
return True | ||
return model_selection.cross_val_predict( |
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.
Is the signature of this one changed? Or why didn't you just import it? Though maybe this is more clear and allows changes in the new function.
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 did this because the order of the labels
parameter was changed in the new module... Previously it was (X, y, cv...)
. At model_selection
, it is (X, y, labels...)
...
looks good except we can't remove |
Yes you are correct! The main reason why the old tests are not removed is exactly that! To allow backward incompatible changes to any of
I feel we can merge this PR as such and re-add the old classes/functions with their old functionality (and ensure that the old tests pass) as and when we make more backward incompatible changes to the The reason why I suggest that this PR be merged is that it is tough to anticipate in advance and retain the old code for all the functions/classes which could get a backward incompatible change in the future. I think it would be easier to copy the old code back in the PR (that does the backward incompatible change) itself. WDYT? @amueller @jnothman @MechCoder |
So you want to remove code and then add it back in later? Why? |
And revisit this PR at the end of all the |
Aka just before 0.18 |
Should we revisit this one now? @amueller |
I'm now +0 on this idea. I don't think there's anything broken here except for contributors changing deprecated files. |
Okay. And there are a lot of changes too. I'm not sure how cleanly we can avoid code duplication... I'm closing this PR. Let me know if this needs to be done... |
Also clean up some of the
cross_validation
andgrid_search
tests.NOTE: Lot more lines can be removed from more redundant tests, but I feel leaving them as such (which will cost a 3-4 extra seconds) will ensure that we haven't regressed on the old modules). To be more clear - if we remove a redundant test for say
cross_val_score
and later modify themodel_selection
's version of the function and test, people using the deprecated module will be surprised by that change since we simply import that frommodel_selection
... Having the test will make sure that such a situation won't happen by failing the old tests and forcing us to leave a copy of the old implementation at the old module...@amueller @vene @jnothman @GaelVaroquaux @ogrisel reviews?