我的数据是一个包含400k观测值的矩阵,其中每个观测值是一行数据,长度为200个元素。我的输出数据是400k 1-hot向量,对应11个输出类。我想格式化我的数据为keras顺序模型。 (Keras 2.0.4,Python 3)
train_values.shape
>>> (400000, 200)
data_labels.shape
>>> (400000, 11)
尝试1:
model = Sequential()
model.add(LSTM(100, input_shape = (200,), return_sequences=True))
model.add(Dense(output_dim=11, input_dim=100, activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
model.fit(train_values, train_labels, batch_size=200, epochs=10)
score = model.evaluate(test_values, test_labels, batch_size=200)
错误1:
----> 3 model.add(LSTM(100, input_shape = (200,), return_sequences=True))
ValueError: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=2
尝试2:
model = Sequential()
model.add(Embedding(400000,200))
model.add(LSTM(100, input_shape = (200,), return_sequences=True))
model.add(Dense(output_dim=11, input_dim=100, activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
model.fit(train_values, train_labels, batch_size=200, epochs=10)
score = model.evaluate(test_values, test_labels, batch_size=200)
错误2:
----> 7 model.fit(train_values, train_labels, batch_size=200, epochs=10)
ValueError: Error when checking target: expected dense_1 to have 3 dimensions, but got array with shape (400000, 11)
结论:输入格式化,调用我的图层或其他完全不知道的错误是我的错误吗?