我已经使用Keras构建了LSTM体系结构,但我不确定复制时间步骤是否是处理可变序列长度的好方法。
我有一个多维数据集,具有多特征序列和不同的时间步长.这是一个多变量时间序列数据,包含多个训练样本,Y值为0或1。目前,我正在复制每个序列的最后一步,以确保timesteps = 3。
如果有人能回答以下问题或关注,我很感激: 1.用零表示的特征值创建额外的时间步骤是否更合适?
# The input sequences are
trainX = np.array([
[
# Input features at timestep 1
[1, 2, 3],
# Input features at timestep 2
[5, 2, 3] #<------ duplicate this to ensure compliance
],
# Datapoint 2
[
# Features at timestep 1
[1, 8, 9],
# Features at timestep 2
[9, 8, 9],
# Features at timestep 3
[7, 6, 1]
]
])
# The desired model outputs is as follows:
trainY = np.array([
# Datapoint 1
[
# Target class at timestep 1
[0],
# Target class at timestep 2
[1] #<---------- duplicate this to ensure compliance
],
# Datapoint 2
[
# Target class at timestep 1
[0],
# Target class at timestep 2
[0]
# Target class at time step 3
[0]
]
])
timesteps = 3
model = Sequential()
model.add(LSTM(3, kernel_initializer ='uniform', return_sequences=True, batch_input_shape=(None, timesteps, trainX.shape[2]),
kernel_constraint=maxnorm(3), name='LSTM'))
model.add(Dropout(0.2))
model.add(LSTM(3, return_sequences=True, kernel_constraint=maxnorm(3), name='LSTM-2'))
model.add(Flatten(name='Flatten'))
model.add(Dense(timesteps, activation='sigmoid', name='Dense'))
model.compile(loss="mse", optimizer="sgd", metrics=["mse"])
model.fit(trainX, trainY, epochs=2000, batch_size=2)
predY = model.predict(testX)发布于 2018-08-07 06:57:54
在我看来,对你的问题有两种解决办法。(重复的时间步骤不是所有这些步骤):
如果你是新手,而绩效并不是很重要,那就选择1。如果你有一个生产环境,你经常需要培训网络,并且它与成本相关,那就试试备选方案2。
https://stackoverflow.com/questions/51720236
复制相似问题