Yes, if you aim to predict an outcome at each time step (i.e., for each visit), your target variable ( y ) should also be a sequence that corresponds to each time step of your inputs. In other words, your ( y ) labels need to be multi-dimensional, matching the temporal dimension of your time-series data (vital_parameters and lab_parameters).
Here's why:
-
Temporal Alignment: For sequence-to-sequence models like LSTMs that make predictions at each time step, the target variable must have the same time dimension as the input sequences. This alignment allows the model to learn the relationship between the input features at each time step and the corresponding target output.
-
Model Output: When your LSTM is configured to return a sequence of outputs (e.g., return_sequences=True in Keras), it produces an output at each time step. To train the model effectively, you need to provide a target value for each of these outputs.
-
Multi-dimensional Targets: If your problem requires predicting multiple features at each time step (e.g., multiple vital signs or lab results), your ( y ) labels should be a 2D array (time steps × features).
Implementation Suggestions:
-
Prepare ( y ) as a Sequence: Ensure your target variable ( y ) is shaped appropriately, typically as a 2D array where one dimension matches the number of time steps and the other matches the number of features you're predicting.
-
Handle Static Parameters: Since static_parameters do not change over time, you'll need to find a way to incorporate them at each time step. One common approach is to repeat or concatenate the static parameters across the time dimension so that they align with the sequences of your dynamic features.
-
Model Architecture:
from keras.models import Model
from keras.layers import Input, LSTM, Dense, Concatenate
# Inputs
vitals_input = Input(shape=(time_steps, vitals_features))
labs_input = Input(shape=(time_steps, labs_features))
static_input = Input(shape=(static_features,))
# LSTM layers
vitals_lstm = LSTM(units)(vitals_input)
labs_lstm = LSTM(units)(labs_input)
# Combine sequences
combined_seq = Concatenate()([vitals_lstm, labs_lstm])
# Repeat static input to match time steps
static_repeated = RepeatVector(time_steps)(static_input)
# Combine with static parameters
combined = Concatenate()([combined_seq, static_repeated])
# Output layer
output = Dense(output_features)(combined)
# Model
model = Model(inputs=[vitals_input, labs_input, static_input], outputs=output)
-
Loss Function: Choose an appropriate loss function that can handle multi-dimensional outputs, such as mean_squared_error for regression tasks or categorical_crossentropy for classification tasks.
-
Batching and Shaping: Ensure that your data is correctly batched and shaped when feeding it into the model. The input shapes should match the expected input shapes specified in your model architecture.
By providing a multi-dimensional ( y ) that corresponds to each time step, you enable the LSTM to learn temporal patterns in your data effectively, leading to better predictions for each visit.
Summary: Since you're predicting at each time step, your target variable ( y ) should indeed be multi-dimensional, containing a target value for each time step in your sequences.
Yes—you need to provide multi-dimensional y_labels with a target value at each time step when predicting per visit.