Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

  • Home
  • Contact Us
  • About Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 437
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 0
Kenil Vasani
Asked: December 11, 20202020-12-11T20:36:53+00:00 2020-12-11T20:36:53+00:00In: Python

Error when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29)

  • 0

My input is simply a csv file with 339732 rows and two columns :

  • the first being 29 feature values, i.e. X
  • the second being a binary label value, i.e. Y

I am trying to train my data on a stacked LSTM model:

data_dim = 29
timesteps = 8
num_classes = 2

model = Sequential()
model.add(LSTM(30, return_sequences=True,
               input_shape=(timesteps, data_dim)))  # returns a sequence of vectors of dimension 30
model.add(LSTM(30, return_sequences=True))  # returns a sequence of vectors of dimension 30
model.add(LSTM(30))  # return a single vector of dimension 30
model.add(Dense(1, activation='softmax'))

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])

model.summary()
model.fit(X_train, y_train, batch_size = 400, epochs = 20, verbose = 1)

This throws the error:

Traceback (most recent call last):
File “first_approach.py”, line 80, in
model.fit(X_train, y_train, batch_size = 400, epochs = 20, verbose = 1)

ValueError: Error when checking model input: expected lstm_1_input to
have 3 dimensions, but got array with shape (339732, 29)

I tried reshaping my input using X_train.reshape((1,339732, 29)) but it did not work showing error:

ValueError: Error when checking model input: expected lstm_1_input to
have shape (None, 8, 29) but got array with shape (1, 339732, 29)

How can I feed in my input to the LSTM ?

keraslstmpythonrecurrent-neural-networkvalueerror
  • 1 1 Answer
  • 9 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Rohit Patel

      Rohit Patel

      • 0 Questions
      • 98 Answers
      • 0 Best Answers
      • 0 Points
      View Profile
      Best Answer
      Rohit Patel
      2020-12-11T20:35:26+00:00Added an answer on December 11, 2020 at 8:35 pm

      Setting timesteps = 1 (since, I want one timestep for each instance) and reshaping the X_train and X_test as:

      import numpy as np
      X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
      X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
      

      This worked!

      • 6
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains ...

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com