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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.