ImportError: No module named model_selection

I guess you have the wrong version of scikit-learn, a similar situation was described here on GitHub. Previously (before v0.18), train_test_split was located in the cross_validation module:

from sklearn.cross_validation import train_test_split

However, now it's in the model_selection module:

from sklearn.model_selection import train_test_split

so you'll need the newest version.

To upgrade to at least version 0.18, do:

pip install -U scikit-learn

(Or pip3, depending on your version of Python). If you've installed it in a different way, make sure you use another method to update, for example when using Anaconda.


Update sklearn:

conda update scikit-learn

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


I encountered this problem when I import GridSearchCV.

Just changed sklearn.model_selection to sklearn.grid_search.