ImportError: No module named model_selection

后端 未结 11 593
攒了一身酷
攒了一身酷 2021-01-30 08:16

I am trying to use train_test_split function and write:

from sklearn.model_selection import train_test_split

and this causes

相关标签:
11条回答
  • 2021-01-30 08:32

    To install scikit-learn version 18.0, I used both commands:

    conda update scikit-learn

    pip install -U scikit-learn

    But it does not work. There was a problem "Cannot install 'scikit-learn'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall".

    Finally, i can install it by using following command:

    pip install --user --upgrade scikit-learn==0.18.0

    0 讨论(0)
  • 2021-01-30 08:35

    Latest Stable release of sklearn 0.20.0 has train_test_split is under model_selection not under cross_validation

    In order to check your sklearn version :

    import sklearn print (sklearn.version) 0.20.2

    0 讨论(0)
  • 2021-01-30 08:37

    I had the same problem while using Jupyter Notebook, no matter what I updated in Python 3, conda, I could not get in Jupyter:

    import sklearn
    print (sklearn.__version__)
    0.17.1
    

    to SHOW scikit-learn-0.18.1

    Finally, I removed Anaconda3 and Jupyter Notebook and reinstalled fresh. I got it to work.

    http://ukitech.blogspot.com/2017/02/sklearnmodelselection.html

    0 讨论(0)
  • 2021-01-30 08:41

    I encountered this problem when I import GridSearchCV.

    Just changed sklearn.model_selection to sklearn.grid_search.

    0 讨论(0)
  • 2021-01-30 08:41

    do you have sklearn? if not, do the following:

    sudo pip install sklearn
    

    After installing sklearn

    from sklearn.model_selection import train_test_split
    

    works fine

    0 讨论(0)
  • 2021-01-30 08:41

    In Late September 2016, SciKit Learn 0.18 was released and there was a slight change to the code. With SciKit Learn 0.18 the train_test_split function is now imported from model_selection instead of cross_validation.

    from sklearn.cross_validation import train_test_split
    

    has been changed to :

    from sklearn.model_selection import train_test_split
    

    The same has also happened for GridSearchCV.

    0 讨论(0)
提交回复
热议问题