I am trying to build an LSTM model to predict temperature for a given day using say past 7 days of temperature, rainfall etc of a Zipcode or PinCode. I understand that the training dataset needs to be shaped as (observations, timesteps, features). I guess the features in my case would be the temperature, rainfall and timesteps would be 7. So If I had 2 features and 7 timesteps, there would be a total of 14 variables for one observation. My question comes when I have features like State, Zone (say North, West, East, Central etc) which are common to all the 7 timesteps. Since each observation is a zipcode, for all 7 days (7 timesteps) of a zipcode, Geographical State & Zone to which the zip code belongs, would be the same. How to specify those common features in a LSTM model in Keras (Python)? Should these features be repeated redundantly for all the timesteps? Is there a better way to specify instead of repeating those features redundantly?


1 Answer 1


You can use a "forked" model, where the LSTM processes the sequential inputs, a FC or other structure processes the tabular inputs, and at some point you concatenate the two vectors to make a single vector. Then the single vector is used to make inferences about the target.

This isn't easy to do in Keras, because it's hard to modify and write novel code for it, but it's dirt-simple to do using Pytorch.

  • $\begingroup$ Thanks for the answer. If I have to do it in Keras itself, will repeating those features for all timesteps work? $\endgroup$
    – Kumar
    May 12, 2020 at 5:20
  • $\begingroup$ No, because the value attributed to repeated features will depend on the length of the time series. $\endgroup$
    – Sycorax
    May 12, 2020 at 16:20

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.