I want to build a LSTM model with one input and two outputs. My data is same as figure. My model is as below. But it only predict one output.
could you help me to design the model for two outputs? thanks
s1 = MinMaxScaler(feature_range=(-1,1))
Xs = s1.fit_transform(train[['y1','y2','x']])
s2 = MinMaxScaler(feature_range=(-1,1))
Ys = s2.fit_transform(train[['y1', 'y2']])
window = 70
X = []
Y = []
for i in range(window,len(Xs)):
X.append(Xs[i-window:i,:])
Y.append(Ys[i])
X, Y = np.array(X), np.array(Y)
model = Sequential()
model.add(LSTM(units=50, return_sequences=True,input_shape=(X.shape[1],X.shape[2])))
model.add(Dropout(0.2))
model.add(LSTM(units=50, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=50))
model.add(Dropout(0.2))
model.add(Dense(units=1))
model.compile(optimizer = 'adam', loss = 'mean_squared_error',metrics = ['MAE'])
es = EarlyStopping(monitor='loss',mode='min',verbose=1,patience=10)
history = model.fit(X, Y, epochs = 10, batch_size = 250, callbacks=[es], verbose=1)
The
output_shape
of the last layer of your model should match the shape of your Y-data.Since you have 2 Y-data, you can change the last Dense layer to have 2 units: