[英]ValueError: Error when checking input: expected lstm_6_input to have shape (87482, 1) but got array with shape (87482, 3)
X_train data dimension is 87482, 3. X_train 数据维度为 87482, 3。
But I got an error on running with the below code.但是使用以下代码运行时出现错误。 The error is:
错误是:
ValueError: Error when checking input: expected lstm_6_input to have shape (87482, 1) but got array with shape (87482, 3)
ValueError:检查输入时出错:预期 lstm_6_input 具有形状 (87482, 1) 但得到的数组具有形状 (87482, 3)
My code is:我的代码是:
model = Sequential()
#model.add(Embedding(top_words, embedding_vecor_length, input_length=max_review_length))
model.add(LSTM(units=3, input_shape=(X_train_rnn.shape[1],1),return_sequences=True))
model.add(LSTM(3, return_sequences=True)) # returns a sequence of vectors of dimension 32
model.add(LSTM(3))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(X_train_rnn, y_train, epochs=2, batch_size=32)
# Final evaluation of the model
scores = model.evaluate(X_test_rnn, y_test, verbose=0)
input_shape=(X_train.shape[1], 1)
should fix the error, but maybe not the entire problem: how long is each sequence ? input_shape=(X_train.shape[1], 1)
应该修复错误,但可能不是整个问题:每个序列有多长?
batch_shape
) is (batch_size, timesteps, channels)
- or, equivalently, (samples, timesteps, features)
batch_shape
) 是(batch_size, timesteps, channels)
- 或者,等效地, (samples, timesteps, features)
batch_size=32
in your .fit()
, but if X_train
dimension is (87472, 3)
, do you have 87472
samples (sequences) each of length 3 ( timesteps=3
)? batch_size=32
在您的.fit()
中,但如果X_train
维度为(87472, 3)
,您是否有87472
样本(序列),每个长度为 3 ( timesteps=3
)? If so, you'll need input_shape=(3, 1)
(univariate data), which is what you get with (X_train.shape[1], 1)
input_shape=(3, 1)
(单变量数据),这就是您得到的(X_train.shape[1], 1)
timesteps=87462
, you'll need input_shape=(87462, 3)
- but this is a pretty bad idea, as LSTMs struggle for timesteps > 0
timesteps=87462
,您将需要input_shape=(87462, 3)
-但这是一个非常糟糕的主意,因为 LSTM 为timesteps > 0
而奋斗I don't know what shapes X_train_rnn
has, so I wrote the answer in terms of X_train
.我不知道
X_train_rnn
有什么形状,所以我用X_train
写了答案。 Feel free to clarify.随时澄清。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.