事件数据的 lstm 时间序列预测

lstm time series prediction for event data

我正在尝试解决时间序列问题。数据集有 n 个系统,我们记录每个系统大约 t 天发生的故障数。然后我的目标是预测任何给定系统在第 t+1 天可能发生的故障数量。 玩具数据集看起来像这样。其中每一行表示一个系统连续11天出现故障的次数。

        x = [[0,1,2,20,24,8,2,2,1,2,1],
             [0,100,200,250,300,80,25,20,10,1,1],
             [1,25,30,35,10,0,0,1,1,0,1],
             [0,10,10,2,24,8,2,2,1,2,1],
             [0,4,20,20,24,80,10,20,30,90,150]]

然后我的训练数据不包括每一行的最后一天。

         x_train = [[0,1,2,20,24,8,2,2,1,2],
             [0,100,200,250,300,80,25,20,10,1],
             [1,25,30,35,10,0,0,1,1,0],
             [0,10,10,2,24,8,2,2,1,2],
             [0,4,20,20,24,80,10,20,30,90]]

我应该如何修改我的数据以使用 LSTM。非常感谢任何示例代码。所有现有代码都对单个实体建模,就像我的情况一样 我有 n 个不同的系统。这是我的简单尝试。请反馈是否符合我的要求。我的数据如下所示。

|    | t1 | t2 | t3 |
|----|----|----|----|
| x1 | 1  | 2  | 3  |   
| x2 | 3  | 4  | 5  |   
| x3 | 5  | 6  | 7  | 
x = np.array([[1,2],[3,4],[5,6]])
y = np.array([[2,3],[4,5],[6,7]])
x = np.reshape(x,(3,1,2))
y = np.reshape(y,(3,2))
test_x  = np.array([[6,7]])
test_x = np.reshape(test_x,(1,1,2))

model = Sequential()  
model.add(LSTM(4,batch_input_shape=(1,1,2), return_sequences=False))
model.add(Dense(2,activation='relu'))
model.compile(loss='mean_absolute_error', optimizer='adam')
model.fit(x, y,nb_epoch= 100, batch_size=1)
model.reset_states()
model.predict(test_x)

谢谢

如果您需要模型来预测 t+1,您只需将数据向右移动 1 个位置即可生成标签。 如果您有数据:[1,2,3,4,5,6,7],并且 seq_len 是 3,例如,您的输入数据批次是 [[1,2,3], [4,5,6]] 您的目标数据批次将是 [[2,3,4],[5,6,7]] 代码可能如下所示:

inputs = np.array(int_text[: n_batches * batch_size * seq_length])
outputs = np.array(int_text[1: n_batches * batch_size * seq_length + 1])

x = np.split(inputs.reshape(batch_size, -1), n_batches, 1)
y = np.split(outputs.reshape(batch_size, -1), n_batches, 1)

编辑:

[[1,2,3], [4,5,6]] 是一个输入批次。 batch_size是2,seq_length是3。

[[2,3,4],[5,6,7]] 是目标批次。 batch_size是2,seq_length是3。

无论使用哪种方法,只要按照上面的方式制作数据即可。