Python Keras LSTM:在预测时返回空数组

Python Keras LSTM:在预测时返回空数组,python,tensorflow,keras,lstm,Python,Tensorflow,Keras,Lstm,我正试着和Keras一起写我的第一篇LSTM,我很结巴。这就是我的训练数据结构:x_数据=[1265,12]y_数据=[1265,3] x_数据示例:[102.7100.69103.3999.619037.035230.01767412102.86,13.98] y_数据示例:[0,0,1] 我的模型如下所示: self._opt_cells = 12 self.model = Sequential() self.model.add(LSTM(units = self.

我正试着和Keras一起写我的第一篇LSTM,我很结巴。这就是我的训练数据结构:x_数据=[1265,12]y_数据=[1265,3]

x_数据示例:
[102.7100.69103.3999.619037.035230.01767412102.86,13.98]
y_数据示例:
[0,0,1]

我的模型如下所示:

    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'])
我用这些代码训练模型:

    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)
但每一个预测都是空洞的。请帮帮我

编辑

我已将培训代码更改为:

    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)

但这不起作用

你有什么错误吗?没有,不幸的是没有……我也有类似的问题:你有什么错误吗?没有,不幸的是没有……我也有类似的问题: