尽管使用sklearn.cross_valid和sklearn.model_selection都出错

时间:2018-07-09 12:11:14

标签: python scikit-learn

从事一些初学者的机器学习编码练习。我陷入sklearn.cross_validation和sklearn.model_selection错误(在我的设置中都不起作用)。这是日志:

Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
Type "copyright", "credits" or "license" for more information.
IPython 2.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.
In [1]: import numpy as np
   ...: import matplotlib.pyplot as plt
   ...: import pandas as pd
In [2]: dataset = pd.read_csv('Salary_Data.csv')
   ...: X = dataset.iloc[:, :-1].values
   ...: y = dataset.iloc[:, 1].values
In [3]: runfile('/home/rocketchef/Machine Learning/Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/simple_linear_regression.py', wdir='/home/rocketchef/Machine Learning/Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression')
Traceback (most recent call last):
  File "<ipython-input-3-2d267c940766>", line 1, in <module>
    runfile('/home/rocketchef/Machine Learning/Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/simple_linear_regression.py', wdir='/home/rocketchef/Machine Learning/Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression')
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/home/rocketchef/Machine Learning/Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/simple_linear_regression.py", line 14, in <module>
    from sklearn.cross_validation import train_test_split
ImportError: No module named sklearn.cross_validation
In [4]: from sklearn.model_selection import train_test_split
   ...: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3, random_state = 0)
Traceback (most recent call last):
  File "<ipython-input-4-931d28d0dd1b>", line 1, in <module>
    from sklearn.model_selection import train_test_split
ImportError: No module named sklearn.model_selection

我在Spyder 2.3.8中使用的iPython 2.4和Python 2.7(如日志中所示)是否可能是问题的根源?我尝试卸载+重新安装甚至更新Spyder,但该程序仍显示上述相同的版本和错误。

0 个答案:

没有答案