Python Sklearn.Model_Selection giving error unable to import comb

Viewed 11573

I am importing train_test_split as:

from sklearn.model_selection import train_test_split and it is giving an error cannot import name 'comb'.

The versions I am using are scipy 0.18.1 and sklearn 0.17.1

Below is the detail of error, please guide here if you feel something is wrong.

   Traceback (most recent call last):

  File "<ipython-input-21-e45e815fd516>", line 1, in <module>
    from sklearn import model_selection

  File "C:\Users\rahulsharma53\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\model_selection\__init__.py", line 1, in <module>
    from ._split import BaseCrossValidator

  File "C:\Users\rahulsharma53\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 31, in <module>
    from ..utils.fixes import signature, comb

ImportError: cannot import name 'comb
1 Answers

The suggestion in the comment above worked for me.

scikit-learn version 0.17.1 doesn't have the 'model-selection' module (it has instead the 'cross_validation' module, reference here). Since you have Anaconda installed, trying to upgrade scikit-learn to the newest version using the pip installer may cause a mismatch with the installed scipy and numpy versions (upgrading them with the pip installer wont solve the problem). The solution is to upgrade all three libraries using anaconda's installer, but before that all existing versions must be uninstalled, first using pip (in case, like me, you already went the pip route) then using conda.

Following the suggestions in the referred link:

pip uninstall:

pip uninstall numpy scipy -y
pip uninstall scikit-learn -y

conda uninstall:

conda uninstall numpy scipy scikit-learn -y

conda install:

conda install numpy scipy scikit-learn -y

Don't forget to restart Anaconda before retrying your import clause.

Related