13

I'm using anaconda , when I import

import sklearn as sk 

It works but when import :

from sklearn.cross_validation import train_test_split

It returns:

No module named 'sklearn.cross_validation'

I checked the environment and scikit-learn is installed what do I need to do?

yousf
  • 191
  • 1
  • 1
  • 4
  • 1
    Possible duplicate of [ImportError: No module named sklearn.cross\_validation](https://stackoverflow.com/questions/30667525/importerror-no-module-named-sklearn-cross-validation) – Amit Gupta Feb 16 '19 at 18:18

5 Answers5

41

As pointed out by @amit-gupta in the question above, sklearn.cross_validation has been deprecated. The function train_test_split can now be found here:

from sklearn.model_selection import train_test_split

Simply replace the import statement from the question to the one above.

Demitri
  • 13,134
  • 4
  • 40
  • 41
7

What's your sklearn version? You can find out with sk.__version__

It's possible that it has been moved to sklearn.model_selection

Ryan Tam
  • 845
  • 5
  • 11
6

For Sklearn 18 version import this: "from sklearn.cross_validation import KFold"

For sklearn 20 import this: "from sklearn.model_selection import KFold"

CFD
  • 607
  • 1
  • 11
  • 29
2

There should be another import:

from sklearn.model_selection import cross_val_score
2

simply replace sklearn.cross_validation with sklearn.model_selection