我使用的是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

我需要做什么?


当前回答

sklearn。Cross_validation现在改为sklearn.model_selection

只使用

from sklearn.model_selection import train_test_split

我想那会有用的。

其他回答

sklearn.cross_validation

已改为

sklearn.model_selection

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

Train_test_split是sklearn模块的一部分。因此,您可能需要从Model_selection导入模块

代码:

from sklearn.model_selection import train_test_split

将数据集分为训练集和测试集

from sklearn.model_selection import train_test_split

Cross_validation在前一段时间已被弃用,请尝试使用model_selection将其替换掉

sklearn。Cross_validation现在改为sklearn.model_selection

只改变

sklearn.cross_validation

to

sklearn.model_selection