# How to make an ensemble model of two LSTM models with different window sizes i.e. different data shapes

Below is the Python code for making an ensemble model. All the inputs are the same for all three models. But what if the models have different input shapes due to different window size, such as LSTM models. So the input shapes for Model A would be (window_size_A, features) and for Model B would be (window_size_B, features). The window sizes are different but the number of features are the same. As such, due to the different window size, the training data of the same dataset is split differently for each model such that the X_train.shape for model A: (train_data_A, window_size_A, output) And for Model B: (train_data_B, window_size_B, output). Note the training data is from the same dataset but the length is different due to the different window size. How would you make an ensemble of these models?

def get_model():
inputs = keras.Input(shape=(128,))
outputs = layers.Dense(1)(inputs)
return keras.Model(inputs, outputs)

model1 = get_model()
model2 = get_model()
model3 = get_model()

inputs = keras.Input(shape=(128,))
y1 = model1(inputs)
y2 = model2(inputs)
y3 = model3(inputs)
outputs = layers.average([y1, y2, y3])
ensemble_model = keras.Model(inputs=inputs, outputs=outputs)

• So this is a question about implementing ensemble learning in Python? – The Pointer Feb 4 at 10:39
• Yes. I guess so. Although any insight in any regard would be welcome and appreciated. – Fruity Feb 4 at 11:37
• Perhaps you could clarify your question and make it more specific? It seems like what you're asking is a bit vague and broad. – The Pointer Feb 4 at 11:48
• Sorry about that. I'm new do this. It is about implementing ensemble learning in Python. And about combining two individual lstm models with different window sizes i.e. time steps. This would be that each model can only receive data in a specific shape, a shape that matches the window size, hence there would need to be more than one input to the ensemble model. – Fruity Feb 4 at 12:08
• How would you make an ensemble of these 2 models: Model1: inputA= Input(shape(window_size_A, features)) hiddenA1= LSTM(units_A1, return_sequences=True)(inputA) hiddenA2 = LSTM(units_A2, activation= 'relu')(hiddenA1) predictionA = Dense(output_A)(hiddenA2) Model2: inputB= Input(shape(window_size_B, features)) hiddenB1= LSTM(units_B1, return_sequences=True)(inputB) hiddenB2 = LSTM(units_B2, activation= 'relu')(hiddenB1) prediction = Dense(output_B)(hiddenB2) – Fruity Feb 4 at 17:37