【发布时间】:2020-01-22 06:11:27
【问题描述】:
我有以下代码sn-p:
X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
model = Sequential()
model.add(LSTM(200, activation='relu', input_shape=(X_train.shape[0], 1, X_train.shape[2]), return_sequences=False))
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(X_train, y_train, epochs=100, batch_size=32)
y_pred = model.predict(X_test)
但是,我收到以下错误:
ValueError: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4
X_train 和 X_test 的原始形状:
X_train: 1483, 13
X_test: 360, 13
在重塑之后它们变成:
X_train: 1483, 1, 13
X_test: 360, 1, 13
我知道这可能是重复的,但网上的答案似乎都不适合我。
【问题讨论】:
标签: keras neural-network time-series lstm