Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/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
Keras 基于lstm的基本时间序列预测_Keras_Lstm_Prediction_Lstm Stateful - Fatal编程技术网

Keras 基于lstm的基本时间序列预测

Keras 基于lstm的基本时间序列预测,keras,lstm,prediction,lstm-stateful,Keras,Lstm,Prediction,Lstm Stateful,我有一个序列,我想用最简单的LSTM来预测序列的其余部分。 这意味着我想从只使用前一步预测下一步开始,然后添加更多步骤。 我想使用预测值作为输入。 所以我相信我想要的是实现答案中提到的多对多 我已经阅读了有关stackoverflow主题的其他问题,但仍然没有成功地使其生效。在我的代码中,我使用这里的教程和函数create_dataset创建两个数组,只需移动一步 这是我的代码和我得到的错误。 您知道我为什么会出现这样的错误吗?因为我似乎做了上述主题中提到的所有事情?在这个LSTM网络中,批处理

我有一个序列,我想用最简单的LSTM来预测序列的其余部分。 这意味着我想从只使用前一步预测下一步开始,然后添加更多步骤。 我想使用预测值作为输入。 所以我相信我想要的是实现答案中提到的多对多

我已经阅读了有关stackoverflow主题的其他问题,但仍然没有成功地使其生效。在我的代码中,我使用这里的教程和函数create_dataset创建两个数组,只需移动一步

这是我的代码和我得到的错误。
您知道我为什么会出现这样的错误吗?因为我似乎做了上述主题中提到的所有事情?

在这个LSTM网络中,批处理大小为1,因为它是有状态的。当stateful=True时,序列集大小和测试集大小除以批次大小时,其模数应为零

batch\u input\u shape=batch\u size,1,1已经定义,那么为什么再次,input\u shape=None,1

当return_sequences=True时,另一个LSTM在现有LSTM层之后。但这里不是

"Here I'm scaling my data as advised"
scaler = MinMaxScaler(feature_range=(0, 1))
Rot = scaler.fit_transform(Rot)

"I'm creating the model using batch_size=1 but I'm not sure why this is necessary"

batch_size = 1
model = Sequential()
model.add(LSTM(1,batch_input_shape=(batch_size,1,1),stateful=True,return_sequences=True,input_shape=(None,1)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')

"I want to use only the previous value for now"
look_back = 1
"as len(Rot) = 41000 I'm taking 36000 for training"
train_size = 36000
X,Y = create_dataset(Rot[:train_size,:],look_back)
X = numpy.reshape(X,(X.shape[0], X.shape[1], 1))
Y = numpy.reshape(Y,(X.shape[0], X.shape[1], 1))

And now I train my network as advised by @Daniel Möller. 

epochs = 10

for epoch in range(epochs):
    model.reset_states()
    model.train_on_batch(X,Y)

" And I get this error "
" PartialTensorShape: Incompatible shapes during merge: [35998,1] vs. [1,1]
     [[{{node lstm_11/TensorArrayStack/TensorArrayGatherV3}}]]."