Reputation: 69
I am trying to write my first LSTM with Keras and i'm stucking. That are my training data structure: x_data = [1265, 12] y_data = [1265, 3]
x_data example: [102.7, 100.69, 103.39, 99.6, 319037.0, 365230.0, 1767412, 102.86, 13.98]
My Model looks like the following:
self.model = Sequential()
self._opt_cells = 12
self.model.add(LSTM(units = self._opt_cells, return_sequences = True, input_shape = (1265, 12)))
self.model.add(Dropout(0.2))
self.model.add(LSTM(units = self._opt_cells, return_sequences = True))
self.model.add(Dropout(0.2))
self.model.add(LSTM(units = self._opt_cells, return_sequences = True))
self.model.add(Dropout(0.2))
self.model.add(LSTM(units = self._opt_cells))
self.model.add(Dropout(0.2))
self.model.add(Dense(3, activation = 'softmax'))
self.model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
This line throwing the error:
cost = self.model.train_on_batch(np.reshape(x_data, [x_data[0], x_data[1], 1]), np.reshape(y_data, [y_data[0], y_data[1], 1]))
I have no idea why i am receiving the error: TypeError : 'list' object cannot be interpreted as an integer
Thanks for help
Upvotes: 0
Views: 291
Reputation: 21
Look at the np.reshape function here: https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html
It says: numpy.reshape(a, newshape, order='C')
The second argument ('newshape') is the shape you wish to convert your array to. In your case, the shape you are converting to is 'x_data[1]' and 'y_data[1]', which is probably a float. As I don't know how your data set looks like, I can not tell you more than this. So, take a closer look at the documentation of the np.reshape function()
Upvotes: 2