【发布时间】:2019-07-14 20:12:09
【问题描述】:
我想在 kaggle 数据集“房价”上使用tensorflow(但没有Keras,在Keras 上,我得到它的工作)构建和训练神经网络。我使用 Python,除了实际训练之外,我的代码运行良好。但是,在训练时,我要么没有错误(但它没有训练),要么得到TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed。
我在 ipynotebook 中在 Google 的 colab 上运行脚本,我认为主要问题在于输入 feed_dict。但是,我不知道这里有什么问题。 batch_X 包含 100x10 特征,batch_Y 具有 100 标签。我想这可能是关键的片段:
train_data = { X: batch_X, Y_:batch_Y }
train_data 是我提供给 sess.run(train_step, feed_dict=train_data") 的内容
这是我的代码:https://colab.research.google.com/drive/1qabmzzicZVu7v72Be8kljM1pUaglb1bY
# train and train_normalized are the training data set (DataFrame)
# train_labels_normalized are the labels only
#Start session:
with tf.Session() as sess:
sess.run(init)
possible_indeces = list(range(0, train.shape[0]))
iterations = 1000
batch_size = 100
for step in range(0, iterations):
#draw batch indeces:
batch_indeces = random.sample(possible_indeces, batch_size)
#get features and respective labels
batch_X = np.array(train_normalized.iloc[batch_indeces])
batch_Y = np.array(train_labels_normalized.iloc[batch_indeces])
train_data = { X: batch_X, Y_: batch_Y}
sess.run(train_step, feed_dict=train_data)
我所希望的是它会运行几分钟并返回优化权重(2 隐藏层,每个48 节点)允许我进行预测。但是,它只是跳过上面的代码或抛出错误。
有人知道出了什么问题吗?
TypeError Traceback (most recent call last)
<ipython-input-536-79506f90a868> in <module>()
13 batch_Y = p.array(train_labels_normalized.iloc[batch_indeces])
14
---> 15 train_data = { X: batch_X, Y_: batch_Y}
16
17 sess.run(train_step, feed_dict=train_data)
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in __hash__(self)
1814 def __hash__(self):
1815 raise TypeError('{0!r} objects are mutable, thus they cannot be'
-> 1816 ' hashed'.format(self.__class__.__name__))
1817
1818 def __iter__(self):
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
【问题讨论】:
-
您的代码适用于我的 Colab 副本?你能编辑你的堆栈跟踪吗?它很难阅读。
-
感谢您的关注,@SıddıkAçıl。出于某种原因,它有时只会出现该错误。我现在重新格式化了回溯并在 Colab 中添加了一些额外的输出。额外的输出清楚地表明模型没有像我希望的那样学习。但是,它确实会迭代。也许优化器和损失函数不能一起工作?我不知道... O_ô 非常感谢任何帮助。
标签: tensorflow training-data kaggle