【发布时间】:2019-10-03 02:22:45
【问题描述】:
我正在研究一个回归问题,我有 12 个传感器数据(独立)列和 1 个输出列,全部以 48KHz 采样。我总共有 420 秒的火车数据。在测试数据集中,我有 12 个传感器数据列,需要预测输出。
到目前为止,我已经尝试过不考虑时间特征的经典机器学习算法。我是时间序列的新手,不确定这是否真的是时间序列预测问题。
我不确定我是否可以将其视为多变量时间序列问题并尝试 LSTM/RNN。 我一直在关注https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/#comment-442845,但无法理解如何预测测试数据。
是否需要追加一个新列将测试数据从 (length,12) 转换为 (length, 13),然后逐行预测并将输出用于下一次迭代?
另外,以上是解决此类问题的正确方法还是我必须考虑其他问题?
更新 在下面的 cmets 上更新我的问题。 假设我的火车数据如下所示(更新标题只是为了更好地解释)。我正在训练与上面链接中提到的相同的 LSTM 网络。我创建了 Y(t),Y(t-1),x1(t-1),x2(t-1),x3(t-1),x4(t-1),x5(t-1), x6(t-1) 使用 series_to_supervised 函数。
Y x1 x2 x3 x4 x5 x6
date
2010-01-02 00:00:00 129.0 -16 -4.0 1020.0 SE 1.79 0
2010-01-02 01:00:00 148.0 -15 -4.0 1020.0 SE 2.68 0
2010-01-02 02:00:00 159.0 -11 -5.0 1021.0 SE 3.57 0
2010-01-02 03:00:00 181.0 -7 -5.0 1022.0 SE 5.36 1
2010-01-02 04:00:00 138.0 -7 -5.0 1022.0 SE 6.25 2
现在,我有没有 Y 列的测试数据。 例如,
x1 x2 x3 x4 x5 x6
date
2010-01-02 00:00:00 -11 -6.0 1020.0 SE 1.79 0
2010-01-02 01:00:00 -12 -1.0 1020.0 SE 2.68 0
2010-01-02 02:00:00 -10 -4.0 1021.0 SE 3.57 0
2010-01-02 03:00:00 -7 -2.0 1022.0 SE 5.36 1
2010-01-02 04:00:00 -7 -5.0 1022.0 SE 6.25 2
我做了什么。我添加了带有 0 填充的假 Y 列,并将第一个值替换为 火车 Y 列的平均值。我的想法是在下一次预测中使用 t-1 预测值。我不知道我怎么能很容易地得到它。我想出了以下逻辑。
代码sn-p
#test_pd is panda frame of size Nx6
#train_pd is panda frame of size Nx5
test_pd['Y'] = 0
train_out_mean = train_pd[0].mean()
test_pd[0][0] = train_out_mean
test_pd = test_pd.values.reshape((test_pd.shape[0],1,test_pd.shape[1]))
out_list = list()
out_list.append(train_out_mean)
for i in range(test_pd.shape[0]):
y = loaded_model.predict(test_pd[i].reshape(1,test_pd.shape[1],test_pd.shape[2]))
y = y[0]
out_list.append(y)
if (i+1>=test_pd.shape[0]):
break
test_pd[i+1][0][0] = y
我有两个后续问题。
上述方法理论上解决问题是否正确?
如果是,那么有没有更好的方法来预测测试数据集?
【问题讨论】:
标签: python machine-learning keras time-series lstm