使用一种热编码输入LSTM

时间:2019-06-19 16:03:06

标签: python keras lstm

时间序列预测:我的数据包含分类值并预测下一个值。使用keras将分类值转换为一种热编码值。

[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]

编码值的形状为

(824,8734)

数据包含1个具有824个时间步长的样本,以预测下一个时间步长。

n_steps=3
n_features=1

LSTM的输入形状是什么?

I tried
X.shape = (824, 8734, 3, 1)
y.shape=(824,8734)
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(n_steps, n_features)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=20, verbose=0)


ValueError: Input 0 is incompatible with layer lstm_3: expected ndim=3, found ndim=4

1 个答案:

答案 0 :(得分:1)

X_train=X_train.reshape(X_train.shape[0],1,X_train.shape[1])
 and input shape is
LSTM(data_dim, input_shape=(time_steps,X_train.shape[2]))