【发布时间】:2019-08-22 01:23:24
【问题描述】:
我有一个 X_train = [(4096, 18464),(4097, 43045),(4098, 38948),(4099, 2095),(4100, 59432),(4101, 55338),(4102, 51245) ,(4103, 26658),(4104, 30755),....] 形状为 (3283, 2) 和
y_train = [19189, 19189, 19189, ..., 1155085434105692417, 1155120620365152513,...] 形状为 (3283, 1)
我使用代码重塑了 X_train:
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]))
得到形状 (3283, 1, 2)
现在我建立了一个 lstm 模型:
data_dim= 2
timesteps=1
num_classes=2
model_pass = Sequential()
model_pass.add(LSTM(units=64, return_sequences=True,
input_shape=(timesteps, data_dim)))
model_pass.add(Dense(2, activation='sigmoid'))
model_pass.compile(loss='binary_crossentropy', optimizer='adam',metrics=['accuracy'])
model_pass.summary()
model_pass.fit(X_train, y_train,batch_size=1, epochs = 1, verbose = 1)
但这给了我一个错误: ValueError: 检查目标时出错:预期dense_24 有3 维,但得到的数组形状为(3283, 1)
谁能告诉我该怎么办?
【问题讨论】:
标签: python arrays lstm reshape