Energy consumption time series forecasting using LSTM model

Jay Patel
3 min readSep 15, 2021

--

The rapid increase in human population and development in technology have sharply raised power consumption in today’s world. Since electricity is consumed simultaneously as it is generated at the power plant, it is important to accurately predict the energy consumption in advance for stable power supply. Time series data are collected based on certain periods which have constants value (hourly, daily, weekly or monthly), it can be used to forecast or predict future circumstance. Prediction is one of the objectives of the time series analysis by identifying the model from previous data and assuming the current information will also occur in the future. The blog presents two approaches with one using a Recurrent Neural Network (RNN) and Long Short Term Memory (LSTM) network, which only considers the previous electricity consumption to predict the 2 month later energy consumption.

Tools / IDE

Google Colab(Jupyter NoteBook)

Software Requirments

  • Python 3.7.7
  • TensorFlow 2.2.0
  • scikit-learn 0.22.2
  • NumPy

Dataset:

Downloaded the dataset from the Kaggle. A time series is a sequence of numerical data points in successive order. These points are often measured at regular intervals (every month, every day, every hour, etc.). The data frequency used in this article is hourly and it was measured from 2004–12–31 to 2018–01–02. The total number of raw data points is 121273.

Visualization of the time series:

The historical data of energy consumed by a building from 2004 to 2018, it is possible for a model to reveal trends and patterns, but also, to predict future energy consumption pattern. As seen in below figure, the data exhibits hourly, daily, yearly patterns,

Energy consumption according to year
According to year(2004,2005,2006)

Then It will calculate mean of value12 and resample the data and display that mean value,

Train the model:

data — the data used for modeling.

epochs — number of training loops (forward propagation to backward propagation cycles). With 50 epochs, the model will be exposed to or pass through the whole dataset . That is a total of 32 batches during the entire training process.

Predictions of electricity consumption process LSTM model parameters are determined by experience of trial and error. set to find the best MSE. The horizontal axis is consumption electricity data and the vertical axis is sum of consumption electricity each data.

The blue graphic is actual and the red one is predicted result. Actual data and prediction have quite different comparison and predicting 2 month later energy consumption.

Comparison between actual and predicted consumption of electricity

--

--

Jay Patel
Jay Patel

Written by Jay Patel

Time will heal all things💫

No responses yet