LSTM shape error when predicting stock prices

Viewed 70

Im following a tutorial on how to predict stock prices with tensor flow. but everytime i run my script i keep getting a shape error

Traceback (most recent call last):
  File "main.py", line 38, in <module>
    model.add(LSTM(units=50, return_sequences=True, input_shape=(x_train.shape[1], 1)))
AttributeError: 'list' object has no attribute 'shape'

I know here on stackoverflow are some similiar answers to this question but to be honest im new to ML so i cant make much sense of the answers given.

The full code is here: https://pastebin.ubuntu.com/p/c4mDKNF3hp/

1 Answers

The input to the neural network must be a numpy array. It seems like you are trying to input a python list. To convert the list into a numpy array do this:

nparray = np.array(python_list)

Do it with both inputs and answers. (x_train and y_train). In your code you are only converting the test data to a numpy array.

It is giving an error because x_train.shape[1] doesn't exist. Python lists don't have a "shape" attribute, numpy arrays do.

Related