0
$\begingroup$

I am trying to build a weather forecasting model. X_train shape :(2970, 1, 9) Y_train shape : (3299675, 1, 4) I am following the (samples_count, timestep, features) rule. The samples_count are my number of data points (these are grids on the map, each grid is a location. There are 9 variables in feature set like temperature, pressure etc.. Target is also a grid of 3299675 points and 4 target variables.

My code

from tensorflow.keras.layers import Input, LSTM, RepeatVector, TimeDistributed, Dense

# Define the number of features in the input and output sequences
n_input_features = 9
n_output_features = 4

# Define the encoder
encoder_inputs = Input(shape=(722, n_input_features))
encoder_lstm = LSTM(50, return_state=True)
encoder_outputs, state_h, state_c = encoder_lstm(encoder_inputs)
encoder_states = [state_h, state_c]

# Define the decoder
decoder_lstm = LSTM(50, return_sequences=True)

# The RepeatVector layer should be used in the following way:
# it repeats the encoder's output (which is a single vector, since return_sequences=False in the encoder)
decoder_inputs = RepeatVector(1000)(encoder_outputs)  # Repeat the encoder output 1000 times

decoder_outputs = decoder_lstm(decoder_inputs, initial_state=encoder_states)
decoder_dense = TimeDistributed(Dense(n_output_features))  # Apply a dense layer to each of the 1000 timesteps
decoder_outputs = decoder_dense(decoder_outputs)

# Define the model that will turn `encoder_inputs` into `decoder_outputs`
model = Model(encoder_inputs, decoder_outputs)

# Compile the model
model.compile(optimizer='adam', loss='mse')```

I am getting error saying the shapes don't match.

Am I doing something wrong? Can LSTM handle this kind of data, if not what can I do to handle variable input and output length. Thank you.
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.