Keras 如何计算LSTM的正确批量?

Keras 如何计算LSTM的正确批量?,keras,deep-learning,time-series,lstm,pytorch,Keras,Deep Learning,Time Series,Lstm,Pytorch,我有一个每日时间序列数据,如下所示 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

我有一个每日时间序列数据,如下所示

            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之间的兑现值和兑现值

我写了一个批量计算器,如下所示

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个每日数据,但我不想丢失这些数据


如何才能正确地执行此操作

我认为你最终总会得到一个不起作用的数字。因为这不是最好的做法。我建议您使用,它可以轻松地为您加载批()。通过将
batch\u size
提供给
Dataloader
它会将数据集拆分为
batch\u size
的最大可能批次,最后一批为