Skip to content

[MRG] Be compatible with newer scikit-learn #199

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

wdevazelhes
Copy link
Member

@wdevazelhes wdevazelhes commented May 10, 2019

Scikit-learn just released their last version 0.21, which does not support python<3.5, so I think we can update the travis script to download the 0.20.3 for python3.4 and python2.7, but still use the newest release for python3.6 (so that we test the behaviour on the new scikit-learn), what do you think ?

Also, there were a few changes that need to be made to work with scikit-learn's new version, which this PR addresses

@wdevazelhes wdevazelhes changed the title Update travis to use previous scikit-learn's versions for older pythons [WIP] Update travis to use previous scikit-learn's versions for older pythons May 10, 2019
@wdevazelhes wdevazelhes changed the title [WIP] Update travis to use previous scikit-learn's versions for older pythons [WIP] Be compatible with newer scikit-learn May 10, 2019
@@ -88,10 +87,6 @@ def check_input(input_data, y=None, preprocessor=None,
is originally 1D and ``ensure_2d`` is True. Setting to 0 disables
this check.

warn_on_dtype : boolean (default=False)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scikit-learn 0.21 deprecates warn_on_dtype (see: scikit-learn/scikit-learn#13324). Since we never use it (except to test it works), I suggest we get rid of it

@wdevazelhes wdevazelhes changed the title [WIP] Be compatible with newer scikit-learn [MRG] Be compatible with newer scikit-learn May 10, 2019
@wdevazelhes wdevazelhes requested review from perimosocordiae, bellet and nvauquie and removed request for perimosocordiae May 10, 2019 13:53
Copy link
Contributor

@perimosocordiae perimosocordiae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good overall, just a few minor comments.

Pretty soon we should probably also drop python2.7 support. I don't remember if we have an issue for that already.

@@ -5,86 +5,108 @@
from sklearn import clone
from sklearn.utils.testing import set_random_state
from test.test_utils import ids_metric_learners, metric_learners
import string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this import used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, indeed

def remove_spaces(s):
s = s.replace(' ', '')
s = s.replace('\n', '')
return s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use a regex here:

return re.sub('\s+', ' ', s)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, it's better
You meant return re.sub('\s+', '', s) to remove the spaces right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, should be an empty replacement string.


def test_lmnn(self):
self.assertRegexpMatches(
str(metric_learn.LMNN()),
r"(python_)?LMNN\(convergence_tol=0.001, k=3, learn_rate=1e-07, "
r"max_iter=1000,\n min_iter=50, preprocessor=None, "
r"regularization=0.5, use_pca=True,\n verbose=False\)")
r"max_iter=1000,\n(\ +)min_iter=50, preprocessor=None, "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\s+ is a bit more readable, IMO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's better, I didn't know \s

ITML_Supervised(A0=None, bounds='deprecated', convergence_threshold=0.001,
gamma=1.0, max_iter=1000, num_constraints=None,
num_labeled='deprecated', preprocessor=None, verbose=False)
""".strip('\n'))
""".strip('\n')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to strip newlines if you're also calling remove_spaces(), right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right indeed

@terrytangyuan
Copy link
Member

Yes, @perimosocordiae here's the issue: #166

@perimosocordiae perimosocordiae added this to the v0.5.0 milestone May 10, 2019
@wdevazelhes
Copy link
Member Author

Thanks for the review @perimosocordiae, I just addressed your comments

str(metric_learn.LMNN()),
r"(python_)?LMNN\(convergence_tol=0.001, k=3, learn_rate=1e-07, "
r"max_iter=1000,(\s+)min_iter=50, preprocessor=None, "
r"regularization=0.5, use_pca=True,(\s+)verbose=False\)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to wrap the whitespace matchers in parens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, done

@perimosocordiae
Copy link
Contributor

+1 to merge when the travis results come back.

Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wdevazelhes
Copy link
Member Author

wdevazelhes commented May 13, 2019

The results are green, merging

@wdevazelhes wdevazelhes merged commit 05a8d41 into scikit-learn-contrib:master May 13, 2019
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.

3 participants