我使用的是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 (从0.20开始,这个包在0.18版本中已弃用,从sklearn import model_selection更改为)。

现在:从sklearn导入model_selection

示例2:

过去:来自sklearn。cross_validation导入cross_val_score(0.18版本已弃用)

现:来自sklearn。导入cross_val_score

其他回答

sklearn。Cross_validation现在改为sklearn.model_selection

只使用

from sklearn.model_selection import train_test_split

我想那会有用的。

cross_validation不再可用。

尝试使用model_selection代替cross_validation:

from sklearn.model_selection import train_test_split

Train_test_split现在在model_selection中。类型:

from sklearn.model_selection import train_test_split

应该可以

sklearn。Cross_validation现在改为sklearn.model_selection

只改变

sklearn.cross_validation

to

sklearn.model_selection

过去:从sklearn.cross_validation (从0.20开始,这个包在0.18版本中已弃用,从sklearn import model_selection更改为)。

现在:从sklearn导入model_selection

示例2:

过去:来自sklearn。cross_validation导入cross_val_score(0.18版本已弃用)

现:来自sklearn。导入cross_val_score