【发布时间】:2019-10-05 16:43:22
【问题描述】:
我有如下的每日时间序列数据。
CashIn CashOut
Date
2016-01-01 0.0 6500.0
2016-01-02 0.0 23110.0
2016-01-03 0.0 7070.0
2016-01-04 0.0 18520.0
2016-01-05 20840.0 22200.0
.
.
.
2019-03-25 59880.0 25500.0
2019-03-26 49270.0 17860.0
2019-03-27 45160.0 48600.0
2019-03-28 39480.0 22840.0
2019-03-29 70260.0 25950.0
2019-03-30 19250.0 24350.0
2019-03-31 46870.0 14400.0
我的总数据量是 1186。我想使用 LSTM 预测 2019-04-01 和 2019-04-30 之间的 CashIn 和 CashOut 值。
我写了一个像下面这样的批处理计算器。
def get_batches(arr, batch_size, seq_length):
batch_size_total = batch_size * seq_length
n_batches = len(arr)//batch_size_total
arr = arr[:n_batches * batch_size_total]
arr = arr.reshape((batch_size, -1))
for n in range(0, arr.shape[1], seq_length):
x = arr[:, n:n+seq_length]
y = np.zeros_like(x)
try:
y[:, :-1], y[:, -1] = x[:, 1:], arr[:, n+seq_length]
except IndexError:
y[:, :-1], y[:, -1] = x[:, 1:], arr[:, 0]
yield x, y
我正在尝试使用 get_batches 函数将此数据集划分为具有 30 个序列长度的批次,因为我有每日时间序列并且我想预测接下来的 30 天。
batches = get_batches(np.array(data_cashIn), 40, 30)
如果我在 get_bathces 函数中写入 39 而不是 40 作为参数,那么我将丢失最近 16 天的数据,但我不想丢失这些数据。
我怎样才能正确地做到这一点?
【问题讨论】:
标签: keras deep-learning time-series lstm pytorch