【发布时间】:2019-04-22 06:26:48
【问题描述】:
我知道这个问题被问了很多次,但我真的无法为我的案例解决这个输入形状问题。
我的 x_train 形状 == (5523000, 13) // (13 个长度为 5523000 的时间序列)
我的 y_train 形状 == (5523000, 1)
类数 == 2
重塑 x_train 和 y_train:
x_train= x_train.values.reshape(27615,200,13) # 5523000/200 = 27615
y_train= y_train.values.reshape((5523000,1)) # I know I have a problem here but I dont know how to fix it
这是我的 lstm 网络:
def lstm_baseline(x_train, y_train):
batch_size=200
model = Sequential()
model.add(LSTM(batch_size, input_shape=(27615,200,13),
activation='relu', return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(128, activation='relu'))
model.add(Dropout(0.1))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation='softmax'))
model.compile(
loss='categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
model.fit(x_train,y_train, epochs= 15)
return model
每当我运行代码时,我都会收到此错误:
ValueError:输入 0 与层 lstm_10 不兼容:预期 ndim=3,发现 ndim=4
我的问题是我在这里缺少什么?
PS:这个项目的想法是我有来自人体13个点的13个信号,我想用它们来检测某种类型的疾病(一种觉醒)。通过使用 LSTM,我希望我的模型根据这 13 个信号来定位我有唤醒的区域。
。
整个数据是 993 名患者,对于每名患者,我使用 13 个信号来检测疾病区域。
如果你想让我把数据放在 3D 维度:
(500000 ,13, 993) # (nb_recods, nb_signals, nb_patient)
对于每个患者,我对 13 个信号进行了 500000 次观察。 nb_patient 是 993
值得注意的是,500000 大小无关紧要!因为我可以让患者观察更多或更少。
更新:这是一位患者的样本数据。
【问题讨论】:
-
您的输入数据到底是什么?你为什么要像
x_train= x_train.values.reshape(27615,200,13)这样重塑你的数据。请提供更多背景信息,最好提供一些 x_train 和 y_train 示例(仅 2 或 3 个)。
标签: python machine-learning neural-network data-mining lstm