重塑输入到 Keras 中的第一层

Reshaping inputs to be fed to first layer in Keras

我正在尝试使用 Keras 实现多元回归,但第一层的输入存在维度不匹配问题。

确切错误:

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 6 but received input with shape [10, 2]

X_trainshape (6860, 2)y_trainshape (6860,)batch_size=10

第一层:

model.add(Dense(32, activation = 'relu', input_dim = 6))

如何重塑输入?

谢谢!

input_dim 是您的数据的维数 - 这里您指定了 6 个维,但您的输入批次只有 2 个维。您最好指定 input_shape=(2),Keras 会自动向其添加批次维度,使其成为 (10, 2)。