Skip to content

[MRG] MAINT: compatibility sklearn 0.20 - #526

Merged
mfeurer merged 10 commits into
openml:developfrom
glemaitre:is/fix_sklearn_flow_test
Sep 20, 2018
Merged

mfeurer merged 10 commits into
openml:developfrom
glemaitre:is/fix_sklearn_flow_test

Conversation

@glemaitre

Copy link
Copy Markdown
Contributor

Make test pass with scikit-learn 0.20

@janvanrijn

Copy link
Copy Markdown
Member

To me it seems that the test-cases should work again (with sklearn 0.18) Please see this travis run.
https://travis-ci.org/openml/openml-python/builds/427758675?utm_source=github_status&utm_medium=notification

I restarted the tests, but they still crash. Anything sklearn > 0.18?

@janvanrijn

Copy link
Copy Markdown
Member

One more crashing apparently:

======================================================================
FAIL: test__get_fn_arguments_with_defaults (tests.test_flows.test_sklearn.TestSklearn)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/openml/openml-python/tests/test_flows/test_sklearn.py", line 756, in test__get_fn_arguments_with_defaults
    self.assertEqual(len(defaults), num_params_with_defaults)
AssertionError: 15 != 16
----------------------------------------------------------------------
Ran 197 tests in 374.796s

@mfeurer mfeurer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot. I only have a few minor questions about this.

Comment thread tests/test_flows/test_flow.py
Comment thread tests/test_flows/test_sklearn.py Outdated
transformer_list=[('ohe', ohe), ('scaler', scaler)])
serialization = sklearn_to_flow(fu)
estimators_names = ('FeatureUnion', 'OneHotEncoder', 'StandardScaler')
for keyword in estimators_names:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the reason to make this test more leniant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We moved some of the transformer from module. Therefore, the serialization name will be incorrect across version of scikit-learn. In the future, it could be as well the case.

I have 2 rermarks:

  • The test was intended to check the presence of the estimator in the serialization, doesn't it? Is it something else in the test which was important to be tested?
  • Speaking with @janvanrijn IRL, currently all scikit-learn estimators are imported with only a single level and no more. All extra level are actually kinda private (some are explicit by putting some "_" at the front of the module name). I think that you should not rely on those extra levels.

To be more specific, you should rely that a user do from sklearn.decompisition import PCA and not from sklearn.decomposition.pca import PCA since pca should be private module.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • The test also intends to check that the name is correctly serialized and does not change (also due to mistakes on our side).
  • Regarding the names: they extra module level might be private, but that's the information we get from the Python interpreter when we ask it for the full module path. Do you have any other suggestion on how to obtain the name(s)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK I see and it makes sense. I don't have a straightforward solution.

The function sklearn.utils.testing could be slightly change or derived to get a mapping from the class name of each estiamtor and the shortest import path. Right now we are using getmembers: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/testing.py#L671

We could think of a try except to get the higher level of import which should not change across version and create this mapping. WDYT?

NB: regarding my previous statement of 2 levels import, I was wrong. We have some estimators which are leaving in the 3rd level (e.g. for feature_extraction for instance).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the idea of having such a mapping is a good idea from the point of view of the OpenML connector, but it needs to live inside of scikit-learn in order to get constant maintenance. For now I suggest to open a new issue in the OpenML-python issue tracker and the scikit-learn issue tracker to keep track of this and get this PR merged. Would you be okay to re-add the string asserts and add to add an if/else statement?

Comment thread tests/test_flows/test_sklearn.py Outdated
'ohe=sklearn.preprocessing.data.OneHotEncoder)')
estimators_names = ('FeatureUnion', 'OneHotEncoder')
for keyword in estimators_names:
self.assertTrue(keyword in estimators_names)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the same question as above applies here.

Comment thread tests/test_flows/test_sklearn.py Outdated
estimators_names = ('FeatureUnion', 'OneHotEncoder', 'StandardScaler')
for keyword in estimators_names:
self.assertTrue(keyword in fu1_serialization.name)
self.assertTrue(keyword in fu2_serialization.name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and here as well.

Comment thread tests/test_flows/test_sklearn.py Outdated
'StandardScaler', 'AdaBoostClassifier',
'DecisionTreeClassifier')
for keyword in estimator_names:
self.assertTrue(keyword in serialized.name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and here, too.

Comment thread tests/test_flows/test_sklearn.py
@glemaitre

Copy link
Copy Markdown
Contributor Author

@mfeurer I answer to the questions. Regarding the less restrictive test, I would be inclined to modify it but I would need a bit more details regarding what actually we should tests there.

@glemaitre

glemaitre commented Sep 20, 2018 via email

Copy link
Copy Markdown
Contributor Author

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