Search code examples
pandasdataframekeraslstmindex-error

Shaping pandas dataframe for LSTM input


I have a simple dataset consisting of only two columns (year and price of oil). Now, I need to shape them in order for keras' LSTM-layer to accept their input_shape.

My code looks like this, I basically need help in the yellow marked area. I think that I need to alter/convert X_train and X_test before (array, normalize, etc.) but I only get errors when trying...

enter image description here

enter image description here

enter image description here


Solution

  • I think your code would work if you keep X_train and X_test as 2 dimensional data frames. So your problem would be solve If you define

    X_train = train[["Year"]]
    X_test = test[["Year"]]
    

    After that you can define you LSTM architecture as you did in the question