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.
Adding some info to the previous answer from @linusg :
sklearn keeps a release history of all its changes. Think of checking it from time to time. Here is the link to the documentation.
As you can see in the documentation for the version 0.18, a new module was created called model_selection. Therefore it didn't exist in previous versions.
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:
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