Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Keras序列模型数据准备:单行观测_Python_Keras_Lstm_Keras Layer - Fatal编程技术网

Python Keras序列模型数据准备:单行观测

Python Keras序列模型数据准备:单行观测,python,keras,lstm,keras-layer,Python,Keras,Lstm,Keras Layer,我的数据是一个400k观测值的矩阵,其中每个观测值是一行数据,长度为200个元素。我的输出数据是400k 1-hot向量,对应11个输出类。我想格式化keras序列模型的数据。(Keras2.0.4,Python 3) 尝试1: model = Sequential() model.add(LSTM(100, input_shape = (200,), return_sequences=True)) model.add(Dense(output_dim=11, input_dim=100, ac

我的数据是一个400k观测值的矩阵,其中每个观测值是一行数据,长度为200个元素。我的输出数据是400k 1-hot向量,对应11个输出类。我想格式化keras序列模型的数据。(Keras2.0.4,Python 3)

尝试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)

结论:是我的输入格式错误、层调用错误,还是我完全不知道的其他错误?

找到了一个有效的解决方案:model=Sequential()model.add(embedded(200,output_dim=200))model.add(LSTM(100))model.add(Dense(num_output_bucket,activation='softmax'))model.compile(optimizer='rmsprop',loss='classifical_crossentropy',metrics=['accurity'])找到了一个有效的解决方案:model=Sequential()model.add(嵌入(200,输出(dim=200))model.add(LSTM(100))model.add(密集(num_输出(bucket,activation='softmax'))model.compile(优化器='rmsprop',loss='classifical_crossentropy',度量=['accurity'])
----> 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)