想导入train_test_split以便将数据集分为测试数据集和训练数据集,但是发生导入错误
我尝试了所有这些,但没有用
conda upgrade scikit-learn
pip uninstall scipy
pip3 install scipy
pip uninstall sklearn
pip uninstall scikit-learn
pip install sklearn
未导入的代码
from sklearn.preprocessing import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=0)
from sklearn.preprocessing import train_test_split
Traceback (most recent call last):
File "<ipython-input-3-e25c97b1e6d9>", line 1, in <module>
from sklearn.preprocessing import train_test_split
ImportError: cannot import name 'train_test_split' from 'sklearn.preprocessing' (C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
答案 0 :(得分:0)
train_test_split
不在preprocessing
中,而是在model_selection
和cross_validation
中,所以您的意思是:
from sklearn.model_selection import train_test_split
或者:
from sklearn.cross_validation import train_test_split