简体   繁体   中英

Predict daily value with LSTM which has hourly timeseries as input

I am training a single layer LSTM that is coded as follows:

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. 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.

  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.

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 . 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]) .

You also have an option to set another argument 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.

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']
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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