简体   繁体   English

使用以每小时时间序列作为输入的 LSTM 预测每日值

[英]Predict daily value with LSTM which has hourly timeseries as input

I am training a single layer LSTM that is coded as follows:我正在训练一个编码如下的单层 LSTM:

model = keras.Sequential()

model.add(keras.layers.LSTM(units=64,
                            input_shape=(X_train.shape[1], X_train.shape[2])))

model.add(keras.layers.Dense(units=1,  activation='sigmoid'))

model.compile(
  loss='binary_crossentropy',
  optimizer = keras.optimizers.Adam(lr=0.0001),
  metrics=['acc']
)

The input to my LSTM is a hourly timeseries.我的 LSTM 的输入是每小时时间序列。 I want to predict values at a daily level based on the hourly series.我想根据每小时系列预测每日级别的值。
Currently what I do is generate hourly predictions and then take the first prediction as the prediction for each day.目前我所做的是生成每小时预测,然后将第一个预测作为每天的预测。 However I wanted to know if there is a way to generate the same prediction at a daily level.但是我想知道是否有办法在日常级别生成相同的预测。
Thank you!谢谢!

You have two options as my opinion.你有两个选择作为我的意见。

  1. Train the model using daily based training data set.使用基于日常的训练数据集训练模型。 When filtering out what the most suitable datapoint for the day is, you can use the datapoint having the greatest number of repeatitions ( mode ) or the mean.在过滤出当天最合适的数据点时,您可以使用重复次数最多的数据点 ( mode ) 或平均值。

  2. Take the outputs hourly based but forecasting 24 outputs for the next 24 hours and get the mean or mode of those 24 as the prediction for the day.以每小时为基础的输出但预测接下来 24 小时的 24 个输出,并获得这 24 个的平均值或众数作为当天的预测。

The best way is probably second one.最好的方法可能是第二种。 It would be much accurate.它会准确得多。

One option is you can also give an argument called batch_input_shape instead of input_shape .一种选择是您还可以提供一个名为batch_input_shape而不是input_shape的参数。 The difference is now you have to give a fixed batch size and your input array shape will look like (24, X_train.shape[1], X_train.shape[2]) .不同之处在于现在您必须提供固定的批量大小,并且您的输入数组形状将类似于(24, X_train.shape[1], X_train.shape[2])

You also have an option to set another argument return_sequences .您还可以选择设置另一个参数return_sequences This argument tells whether to return the output at each time step instead of the final time step .这个参数告诉是否在每个时间步而不是最后一个时间步返回输出。 As we set the return_sequences to True , the output shape becomes a 3D array, instead of a 2D array.当我们将return_sequences设置为True ,输出形状变为 3D 数组,而不是 2D 数组。

model = keras.Sequential()

model.add(keras.layers.LSTM(units=64,
                            batch_input_shape=(24, X_train.shape[1], X_train.shape[2])))

model.add(keras.layers.Dense(units=1,  activation='sigmoid'))

model.compile(
  loss='binary_crossentropy',
  optimizer = keras.optimizers.Adam(lr=0.0001),
  metrics=['acc']
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM