I have a dataset of hourly measures of pollution('Sample_Measurement) and weather condition. If I want to predict the pollution level of the current hour using the weather and pollution data of the previous n hours i have no problem. In fact, let's say that n = 24 and the number of features is 5. The 3D vectors will have the following shape (number of elements, 24,5). enter image description here

Until this point I have no problem, but what i want to do is using also the weather condition of the current hour(together with the previous n = 24 hours), since in the previous case I was using only the data for the previous n hours. The problem is that i don't know how to do it since the 3D vector has as third dimension 5 (4 weather features plus 1 one that represents the pollution level), so i cannot simply add the current hour weather features because the number of feature(4) is different(since for the current hour we don't have the current pollution that is what we want to predict) from 5. I hope I have been clear but it was not easy to explain.


1 Answer 1


What you could try to do is the following (pseudocode ahead):

input_past_24 = Input(shape=(24,5))
input_today = Input(shape(1,4))
output_from_LSTM = LSTM(some_args, ...)(input_past_24) # this has some size of your choice, let's say N
# if you want to add other layers, you'd do it here.
prediction = Dense(some_args, ...)(concatenate(input_today,output_from_LSTM))
model = Model(inputs=[input_past_24,input_today], output=prediction)
model.fit([data_from_past_days,data_today],expected_pollution, some_other_args...)

Above, the crucial point is to concatenate the output of the LSTM layer with the input of the day, before sending this to a final Dense layer for the final prediction.

For extra details, you may want to check Keras' Guide to the functional API.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.