【发布时间】:2020-02-18 23:21:00
【问题描述】:
我有一个数据集,其中包含许多及时的快照观察和一个 1 或 0 作为每个观察的标签。假设每个观察包含 3 个特征。我想训练一个 LSTM,它将接受一系列 n 观察并尝试将第 n 个观察分类为 1 或 0。
如果我们有一个如下所示的数据集:
# X = [[0, 1, 1], [1, 0, 0], [1, 1, 1], [1, 1, 0]]
# y = [1, 0, 1, 0]
# so X[0] = y[0], X[1] = y[1]
# . and I would like to input X[0] + X[1] to classify X[1] as y[1]
# . How would I need to structure this below?
X = [[0, 1, 1], [1, 0, 0], [1, 1, 1], [1, 1, 0]]
y = [1, 0, 1, 0]
def create_model():
model = Sequential()
# input_shape[0] is equal to 2 timesteps?
# input_shape[1] is equal to the 3 features per row?
model.add(LSTM(20, input_shape=(2, 3)))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
m = create_model()
m.fit(X, y)
所以我希望 X[0] 和 X[1] 成为一次训练迭代的输入,并应归类为 y[1]。
我的问题是这样的。如何构建模型以正确获取此输入?我对input_shape、features、input_length、batches 等感到非常困惑……
【问题讨论】:
标签: pandas numpy keras deep-learning lstm