【发布时间】:2019-03-16 07:34:20
【问题描述】:
在构建新的神经网络时 我似乎无法拆分数据。 由于某些未知原因,它不会导入 train.test.split
ImportError: 无法导入名称“cross_validation”
#split dataset in result y and data X
X = np.array(df.drop(['Survived'],1)) # not sure why this wasnt needed
y = np.array(df['Survived'])
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X,y,test_size=0.2)
我尝试了各种方法来导入该 sklearn 函数(已标记):
#from sklearn.model_selection import GridSearchCV, KFold
#from sklearn import module_selection # => cross_validation.train_test_split
#from sklearn import cross_validation
#from sklearn.svm.libsvm import cross_validation
#from sklearn import preprocessing, cross_validation
from sklearn import preprocessing, cross_validation
#here are the machine algorythms
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.naive_bayes import GaussianNB #added myself (https://machinelearningmastery.com/compare-machine-learning-algorithms-python-scikit-learn/)
from sklearn import model_selection
from sklearn.metrics import classification_report, accuracy_score
我的背景我是 python 初学者, 我在 C# 中制作了手动(从头开始)神经网络 RNN LSTN,但不是在 python 中 现在我想参加 kaggle Titanic 挑战(所以我不能在这里发布我所有的代码,但我只展示这个问题区域)
使用的版本:
蟒蛇:3.6.6
python : 由 conda-forge 打包
python :(默认,2018 年 7 月 26 日,11:48:23)[MSC v.1900 64 位 (AMD64)]
keras:配置为 > tensorflow 1.9.0
熊猫:0.23.4
numpy : 1.15.2
sklearn:0.20.0
matplotlib:3.0.0
附加说明,该函数本身可以在其他使用相同内核的 jupyter notebook 中工作,(我什至尝试过他们的导入行)但现在它不工作了。
【问题讨论】:
-
不,我不这么认为,我得到的错误是:ImportError: cannot import name 'cross_validation'
-
只需导入
model_selection代替cross_validation并使用model_selection.train_test_split。 -
你确定当你说
"yes i'm sure both use the same Kernel TensorF"时,这意味着另一个笔记本实际上也在导入cross_validation模块并且没有被注释掉。