I want to train an LSTM model to predict two variables from two input variables.
X and Y will contain the same data. Here an example of X:
array([[41.39084204, 2.16312765],
[41.39063094, 2.16710319],
[41.39048993, 2.16705291],
...,
[41.3937295 , 2.16270432],
[41.39130639, 2.16328958],
[41.39079175, 2.16311477]])
I convert it to three dimensions [x.reshape(x.shape[0], x.shape[1], 1)]:
array([[[41.39084204],
[ 2.16312765]],
[[41.39063094],
[ 2.16710319]],
[[41.39048993],
[ 2.16705291]],
...,
[[41.3937295 ],
[ 2.16270432]],
Then, I set up the layers of input in_dim (2, 1) [(x.shape[1], x.shape[2])] and output out_dim 2 [y.shape[1]]. After configuring the model
model = Sequential()
model.add(LSTM(64, input_shape=in_dim, activation="relu"))
model.add(Dense(out_dim))
model.compile(loss="mse", optimizer="adam")
And fiting it:
model.fit(xtrain, ytrain, epochs=100, batch_size=12, verbose=0)
The content of xtest is:
array([[41.39059914],
[ 2.16686587]])
with shape (2,1)
I get this prediction from a single sample :
ypred = model.predict(xtest)
ypred
WARNING:tensorflow:Model was constructed with shape (None, 2, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, 2, 1), dtype=tf.float32, name='lstm_16_input'), name='lstm_16_input', description="created by layer 'lstm_16_input'"), but it was called on an input with incompatible shape (None, 1, 1).
array([[0.56766266, 2.1052783 ],
[0.05906536, 0.03917462]], dtype=float32)
However, the output doesn't look like the imput. Any idea?