Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t获取多元LSTM的正确输入维度_Python_Tensorflow_Keras_Deep Learning_Lstm - Fatal编程技术网

Python Can';t获取多元LSTM的正确输入维度

Python Can';t获取多元LSTM的正确输入维度,python,tensorflow,keras,deep-learning,lstm,Python,Tensorflow,Keras,Deep Learning,Lstm,我正在尝试使用LSTM为时间序列预测问题训练一个递归神经网络,但是我在获得正确的输入维度时遇到了困难 数据是大约50家商店和数千件商品的每月商店销售额。目标是每个商品/商店组合的月销售额,没有延迟。训练集是前4个时间步。最后是验证。(原始数据集为31个月) 我认为我的输入数据是正确的(示例、时间步、功能),我目前的目标是(示例、时间步),但我不确定。我的想法是 如果有人看到我收到的错误信息并给出建议,我将不胜感激 data = data.reshape(521398,4,28) #targets

我正在尝试使用LSTM为时间序列预测问题训练一个递归神经网络,但是我在获得正确的输入维度时遇到了困难

数据是大约50家商店和数千件商品的每月商店销售额。目标是每个商品/商店组合的月销售额,没有延迟。训练集是前4个时间步。最后是验证。(原始数据集为31个月)

我认为我的输入数据是正确的(示例、时间步、功能),我目前的目标是(示例、时间步),但我不确定。我的想法是 如果有人看到我收到的错误信息并给出建议,我将不胜感激

data = data.reshape(521398,4,28)
#targets = targets.reshape(521398,4,1)


xt = data[:,:4,:]
xv = data[:,4:,:]
yt = targets[:,:4]
yv = targets[:,4:]

print(data.shape, targets.shape)
(521398,4,28)(521398,4)

这会引发错误:

ValueError回溯(最近一次调用上次) 在() ---->1历史=model.fit(xt,yt,批次大小=4096,年代=20,验证数据=(xv,yv))

2帧 /usr/local/lib/python3.6/dist-packages/keras/engine/training\u utils.py标准化输入数据(数据、名称、形状、检查批处理轴、异常前缀) 139':预期“+名称[i]+”具有形状”+ 140 str(shape)+“但是得到了具有shape的数组”+ -->141 str(数据_形)) 142返回数据 143

ValueError:检查输入时出错:预期lstm_1_输入具有形状(4,28),但获得具有形状(0,28)的数组


我认为检查
xv
数组的形状会有帮助。
数据
数组的形状是
(521398,4,28)
,但在后面的部分中,您试图分配
xv=data[:,4:,:]
,如果我没有弄错的话,这可能会导致
xv
@ManikTharaka的数组为空。非常感谢,我不相信这就是问题所在
import tensorflow as tf 
from keras.models import Sequential
from keras.layers import LSTM,Dense,Dropout
from keras import models
from keras import layers

model = Sequential()

model.add(LSTM(256, activation = 'relu', input_shape = (4,28)))
model.add(Dropout(0.4))
model.add(Dense(4,))

model.compile(loss = 'mse', optimizer = 'adam', accuracy = 'mae')

history = model.fit(xt,yt,batch_size = 4096, epochs = 20,validation_data = (xv, yv))