Keras LSTM: Return Empty Array on Predicition

喜夏-厌秋 提交于 2021-01-28 05:20:31

问题


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] y_data example: [0, 0, 1]

My model looks like the following:

    self._opt_cells = 12
    self.model = Sequential()

    self.model.add(LSTM(units = self._opt_cells, return_sequences = True, input_shape = (12, 1)))
    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'])

And with this code i train the model:

    x_data = np.reshape(x_data, (x_data.shape[0], 12, 1))
    y_data = np.reshape(y_data, (y_data.shape[0], 3))
    for e in range(100): 
        cost = self.model.train_on_batch(x_data, y_data)

    prediction = self.model.predict(x_data)

But every prediction is empty. Please Help me!

Edit

I have changed the code of the training to:

    x_data = np.reshape(x_data, (x_data.shape[0], 1))
    y_data = np.reshape(y_data, (y_data.shape[0]))

    self.model.fit(x_data, y_data, epochs = 50, batch_size = 8)

But that dont works

来源:https://stackoverflow.com/questions/59735663/keras-lstm-return-empty-array-on-predicition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!