Dimension Mismatch in LSTM Keras

无人久伴 提交于 2019-12-05 09:39:08

In Keras the Sequential models expect an input of shape (batch_size, sequence_length, input_dimension). I suspect you need to change the two last dimensions of your input array. Remember, the batch dimension is not explicitly defined.

Change X to [[[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]]] so that its shape is (1, 8, 2)

Keras as input requiers 3D data, as stated in error. It is samples, time steps, features. Since you have (8L, 2L) Keras takes it as 2D - [samples, features]. In order to fix it, do something like this

def reshape_dataset(train):
    trainX = numpy.reshape(train, (train.shape[0], 1, train.shape[1]))
    return numpy.array(trainX)

x = reshape_dataset(your_dataset)

now X should be 8L,1,2L which is [samples, time steps, features] - 3D

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