Skip to content
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

scikit-learn 0.20.0 breaks sklearn-genetic 0.2 #11

Closed
john-sandall opened this issue Jul 4, 2020 · 5 comments
Closed

scikit-learn 0.20.0 breaks sklearn-genetic 0.2 #11

john-sandall opened this issue Jul 4, 2020 · 5 comments

Comments

@john-sandall
Copy link

Environment Versions

  1. OS Type: macOS Mojave (10.14.6)
  2. Python version: Python 3.6.8
  3. pip version: pip 18.1
  4. sklearn-genetic version: 0.2

Steps to replicate

  1. I'm using pyenv and virtualenv to control Python environment, so for exact replication, pyenv shell 3.6.8 and mkvirtualenv sklearn-genetic-test to create fresh virtualenv.
  2. pip install sklearn-genetic==0.2
  3. In a Python shell, run from genetic_selection import GeneticSelectionCV

Expected result

Running from genetic_selection import GeneticSelectionCV works without error.

Actual result

(sklearn-genetic-test) ➜  sklearn-genetic-test python
Python 3.6.8 (default, May 22 2020, 14:02:32)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from genetic_selection import GeneticSelectionCV
/Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/sklearn/utils/deprecation.py:143: FutureWarning: The sklearn.metrics.scorer module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
  warnings.warn(message, FutureWarning)
/Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/sklearn/utils/deprecation.py:143: FutureWarning: The sklearn.feature_selection.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.feature_selection. Anything that cannot be imported from sklearn.feature_selection is now part of the private API.
  warnings.warn(message, FutureWarning)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/genetic_selection/__init__.py", line 32, in <module>
    from sklearn.externals.joblib import cpu_count
ModuleNotFoundError: No module named 'sklearn.externals.joblib'
>>> quit()
(sklearn-genetic-test) ➜  sklearn-genetic-test pip -V
pip 18.1 from /Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/pip (python 3.6)
(sklearn-genetic-test) ➜  sklearn-genetic-test python -c "from genetic_selection import GeneticSelectionCV"
/Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/sklearn/utils/deprecation.py:143: FutureWarning: The sklearn.metrics.scorer module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
  warnings.warn(message, FutureWarning)
/Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/sklearn/utils/deprecation.py:143: FutureWarning: The sklearn.feature_selection.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.feature_selection. Anything that cannot be imported from sklearn.feature_selection is now part of the private API.
  warnings.warn(message, FutureWarning)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/john/.virtualenvs/sklearn-genetic-test/lib/python3.6/site-packages/genetic_selection/__init__.py", line 32, in <module>
    from sklearn.externals.joblib import cpu_count
ModuleNotFoundError: No module named 'sklearn.externals.joblib'
@john-sandall
Copy link
Author

This is happening because in scikit-learn 0.20.0 they relocated sklearn.externals.joblib to from sklearn.utils._joblib import cpu_count (see https://scikit-learn.org/dev/whats_new/v0.20.html#miscellaneous).

The easiest fix here is to simply state that sklearn-genetic only works with scikit-learn>=0.20.0. If you want to add backwards compatibility to 0.18 then you'll need some conditional logic to check the sklearn version in order to determine where to import cpu_count from.

For now I can give you a PR which gets this library working again and pip installable via PyPI. There are further issues for getting this working with Python 3.8 which I shall detail in a separate issue.

@john-sandall
Copy link
Author

john-sandall commented Jul 4, 2020

Another reason to simply require scikit-learn>=0.20.0 is because scitki-learn version 0.18 doesn't follow modern Python packaging conventions in that it doesn't specify or automatically install numpy and scipy as required sub-dependencies, instead requiring the user to manually install these in their environment first.

See scikit-learn/scikit-learn#7867 and scikit-learn/scikit-learn#8242 for discussion of this problem and why it existed. This was resolved in sklearn 0.20 - https://github.com/scikit-learn/scikit-learn/blob/0.20.0/setup.py

In certain situations, this may cause issues with even installing sklearn-genetic==0.2, e.g. if someone does indeed want to use scitkit-learn==0.18 and uses pip-tools to pin the version, pip-tools won't put numpy or scipy in it's auto-generated requirements.txt due to sklearn 0.18 not correctly specifying them as requirements, which means the installation fails. This was an issue I faced when trying to test to see how hard it would be to make this package work for both 0.18 and >=0.20.0

@adajinjin
Copy link

Similar issue here. It looks like with higher version of sklearn this issue still exists.
Python version: 3.7.7
scikit-learn==0.23.0
sklearn-genetic==0.2
Same error message:
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 from genetic_selection import GeneticSelectionCV

~/opt/anaconda3/envs/recommender/lib/python3.7/site-packages/genetic_selection/init.py in
30 from sklearn.metrics.scorer import check_scoring
31 from sklearn.feature_selection.base import SelectorMixin
---> 32 from sklearn.externals.joblib import cpu_count
33 from deap import algorithms
34 from deap import base

ModuleNotFoundError: No module named 'sklearn.externals.joblib'

@john-sandall
Copy link
Author

@adajinjin I need to make a couple changes to #12 after which I think @manuel-calzolari will accept #12 and maybe #13. In the meantime, you can always install from my fork here: https://github.com/john-sandall/sklearn-genetic/

@manuel-calzolari
Copy link
Owner

Closed with commit c029c0e.

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 a pull request may close this issue.

3 participants