Stateful LSTM with Keras — predicting electricity consumption

In this example, we predict electricity consumption for a consumer using a stateful and stateless LSTM network and compare their behaviors. As you will recall, RNNs in Keras are stateless by default. In case of stateful models, the internal states computed after processing a batch of input is reused as initial states for the next batch. In other words, the state computed from element i in a batch will be used as initial state for for the element i in the next batch.

The dataset we will use is the electricity load diagram dataset from the UCI Machine Learning Repository (, and contains consumption information ...

Get Deep Learning with Keras now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.