当前位置:   article > 正文

keras上手系列之:序列到序列预测问题_lstm many to many

lstm many to many

LSTM序列到序列模型种类

LSTM 序列到序列(seq to seq)问题建模, 根据问题和数据本身的特点,可以分为几种不同:
- 一对一(one to one)
- 多对一(many to one)
- 一对多(one to many)
- 多对多(many to many)

一个时间步预测

(1) 一对一(one to one)
这种模型是根据过去的一个时间点上的数据,预测下一个时间点的数据. 典型的问题结构是:
y(t+1) = f(x(t))
对应的LSTM网络结构是:
这里写图片描述
按照timestep展开后, 网络结构如下:
这里写图片描述
一对一模型用keras建模实现如下:

model = Sequential()
model.add(LSTM(..., input_shape=(1, features)))
model.add(Dense(1))
  • 1
  • 2
  • 3

值得注意的是, 数据本身可以是一个向量, 也就是说, 在一个时间点上, 对应的数据本身是多维的.
整个网络的输入是1个长度为features的向量, 输出是标量。
(2) 多对一(many to one)
此时,网络输入的时间步是大于1的, 但是输出的预测时间步只是1.
y(t+1) = f(x(t-n), x(t-n+1), …, x(t))
此时的网络结构为:
这里写图片描述

model = Sequential()
features = 10
vectors = 3
model.add(LSTM(8, input_shape=(vectors, features)))
model.add(Dense(1))
print(model.summary())
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

可以得到:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_27 (LSTM)               (None, 8)                 608       
_________________________________________________________________
dense_22 (Dense)             (None, 1)                 9         
=================================================================
Total params: 617
Trainable params: 617
Non-trainable params: 0
______________________________
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/47390?site
推荐阅读
相关标签
  

闽ICP备14008679号