【发布时间】:2020-10-01 09:15:21
【问题描述】:
我正在尝试建立一个模型来根据 3 个观察的序列预测 4 个值,即:
如果以下是数据
+--------------------------------+
|feature |feature |feature |Value|
+--------------------------------+
|0.1 |0.1 |0.1 |1 |
+--------------------------------+
|0.2 |0.2 |0.2 |2 |
+--------------------------------+
|0.3 |0.3 |0.3 |3 |
+--------------------------------+
|0.4 |0.4 |0.4 |4 |
+--------+--------+--------+-----+
我想预测 [1,2,3,4] 基于
+--------------------------+
|feature |feature |feature |
+--------------------------+
|0.1 |0.1 |0.1 |
+--------------------------+
|0.2 |0.2 |0.2 |
+--------------------------+
|0.3 |0.3 |0.3 |
+--------+--------+--------+
我的X,y形状如下(1228, 3, 19) (1228, 4, 1)
def get_model():
model = Sequential()
model.add(LSTM(32, activation='tanh', return_sequences=True, input_shape=(X.shape[1], X.shape[2]))),
model.add(Dense(32, activation='relu')),
model.add(Dense(4, activation='sigmoid'))
model.compile(loss='mse', optimizer="adam", metrics=['mae', 'mse'])
return model
My Model code:
Model: "sequential_17"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_17 (LSTM) (None, 3, 32) 6656
_________________________________________________________________
dense_34 (Dense) (None, 3, 32) 1056
_________________________________________________________________
dense_35 (Dense) (None, 3, 4) 132
=================================================================
Total params: 7,844
Trainable params: 7,844
Non-trainable params: 0
_________________________________________________________________
当我尝试拟合数据时:
history = model.fit(X_train, y_train, epochs=200, batch_size=64, validation_split=0.2, verbose=0, callbacks=[tensorboard_callback])
我收到以下错误:
ValueError: Dimensions must be equal, but are 3 and 4 for
我应该如何重塑我的数据以使其正常工作,我应该填充缺失的序列吗?
【问题讨论】:
-
你的
X怎么可能是3维的?如果您有 1228 个样本,每个样本有 3 个特征(如您展示的示例所示),则其形状应为(1228, 3); 19的第三维是什么?同样,y的形状应该只是(1228,)(features 不应该是 value 的一部分)。 -
1228 组,每组 3 天,每组 19 个功能。在我的问题中,我简化了数据集
标签: python machine-learning keras lstm