我使用的是Ubuntu 14.04中的python 2.7。我用这些命令安装了scikit-learn, numpy和matplotlib:

sudo apt-get install build-essential python-dev python-numpy \
python-numpy-dev python-scipy libatlas-dev g++ python-matplotlib \
ipython

但是当我导入这些包时:

from sklearn.cross_validation import train_test_split

它返回给我这个错误:

ImportError: No module named sklearn.cross_validation

我需要做什么?


当前回答

cross_validation不再可用。

尝试使用model_selection代替cross_validation:

from sklearn.model_selection import train_test_split

其他回答

它必须与model_selection的cross_validation子模块的重命名和弃用有关。尝试将cross_validation替换为model_selection

sklearn.cross_validation

已改为

sklearn.model_selection

在这里查看文档: https://scikit-learn.org/stable/modules/cross_validation.html

我猜交叉选择已经不活跃了。我们应该用模型选择来代替。您可以从sklearn编写它来运行。导入train_test_split

这是它。

Train_test_split现在在model_selection中。类型:

from sklearn.model_selection import train_test_split

应该可以

像这样更改代码

# from sklearn.cross_validation import train_test_split
from sklearn.model_selection import train_test_split