0% found this document useful (0 votes)
25 views37 pages

Report 13

Uploaded by

Vinuthna Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views37 pages

Report 13

Uploaded by

Vinuthna Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

ENERGY CONSUMPTION FORECASTING

USING DEEP LEARNING

A report submitted in partial fulfillment of the requirements for the Degree of


Bachelor of Technology
in
Computer Science and Engineering

By

B Arjun Reddy 2111CS010061


U Aman Kumar 2111CS010039
K Anirudh Reddy 2111CS010045
S Bharath 2111CS010085
K Bhargava Chary 2111CS010089

Under the esteemed guidance of


Dr P.Rambabu

Department of Computer Science & Engineering

School of Engineering
MALLA REDDY UNIVERSITY
Maisammaguda, Dulapally, Hyderabad, Telangana 500100
2024
Department of Computer Science and Engineering

CERTIFICATE

This is to certify that this is the Application development lab record entitled “Energy
Consumption Forecasting Using Deep Learning”, submitted by B.Arjun Reddy
(2111CS010061) , U.Aman Kumar(2111CS010039), K.Anirudh
Reddy(2111CS010045), S.Bharath (2111CS010086), K.Bhargava
Chary(2111CS010089 ),towards the partial fulfillment for the award of Bachelor’s
Degree in (Course name) from the Department of Computer Science and Engineering,
Mall Reddy University, Hyderabad, is a record of bonafide work done by him/her. The
results embodied in the work are not submitted to any other University or Institute for
award of any degree or diploma.

Internal Guide Head of the Department


Dr P.Rambabu Dr. Shaik Meeravali

External Examiner

i
DECLARATION

I declare that this project report titled “Energy Consumption Forecasting Using Deep
Learning” has been carried out by us and this work has been submitted to the Department
of Computer Science and Engineering, Malla Reddy University, Hyderabad in partial
fulfillment of the requirements for the award of degree of Bachelor of Technology. We
further declare that this project work has not been submitted in full or part for the award of
any other degree in any other educational institutions.

Place: Hyderabad Date:

B Arjun Reddy 2111CS010061


U Aman Kumar 2111CS010039
K Anirudh Reddy 2111CS010045
S Bharath 2111CS010086
K Bhargava Chary 2111CS010089

ii
ACKNOWLEDGEMENT

We extend our sincere gratitude to all those who have contributed to the completion of this project
report. Firstly, we would like to extend our gratitude to Dr. V. S. K Reddy, Vice- Chancellor, for
his visionary leadership and unwavering commitment to academic excellence.

We would also like to express my deepest appreciation to our project guide Dr P.Rambabu,
Professor, whose invaluable guidance, insightful feedback, and unwavering support have been
instrumental throughout the course of this project for successful outcomes.

We are also grateful to Dr.Meeravali Shaik, Head of the Department of Computer Science and
Engineering, for providing us with the necessary resources and facilities to carry out this project.

My heartfelt thanks also go to Dr. Harikrishna Kamatham, Dean ,School of Engineering for his
guidance and encouragement.

We are deeply indebted to all of them for their support, encouragement, and guidance, without
which this project would not have been possible.

B Arjun Reddy 2111CS010026


U Aman Kumar 2111CS010042
K Anirudh Reddy 2111CS010051
S Bharath 2111CS010080
K Bhargava Chary 2111CS010074

iii
ABSTRACT

In the present era, due to technological advances, the problem of energy consumption has
become one of the most important problems for its environmental and economic impact. Energy
consumption forecasting is crucial for optimizing energy distribution, reducing costs, and
minimizing environmental impacts.. This project explores the use of deep learning techniques to
enhance the accuracy and reliability of energy consumption predictions. In this project we
develop and evaluate Long Short-Term Memory (LSTM) to capture temporal dependencies and
identify patterns in historical energy usage data. The models are trained and tested on real-world
datasets of Telangana. Our findings demonstrate that deep learning models, particularly LSTM
networks, outperform traditional approaches in forecasting accuracy, especially in handling
seasonal variations. The project underscores the potential of deep learning to revolutionize
energy management, enabling more efficient resource allocation and contributing to the
development of smart grids.

iv
CONTENTS

DESCRIPTION PAGE NO

CERTIFICATE i

DECLARATION ii

ACKNOWLEDGEMENTS iii

ABSTRACT iv

LIST OF FIGURES vii

LIST OF ACRONYMS AND DEFINITIONS ix

Chapter 1 INTRODUCTION 1-3

1.1 Introduction 1

1.2 Objective 2

1.3 Overview 2-3

CHAPTER 2 LITERATURE SURVEY 4

CHAPTER 3 SYSTEM ANALYSIS 5-6

2.1 Existing System 5

2.2 Proposed System 5-6

CHAPTER 4 SYSTEM REQUIREMENTS & 7-15


SPECIFICATIONS

4.1 Database 7

4.2 Design 8-13

4.2.1 System Architecture 8

4.2.2 Data Flow Diagram 8


4.2.3 Use Case Diagram 9

4.2.4 Class Diagram 9

v
4.2.5 Sequence Diagram 10

4.2.6 Activity Diagram 10

4.3 Modules 11-12

4.3.1 Modules Description 11-12

4.4 System Requirements 12-13

4.4.1 Hardware Requirements 12

4.4.2 Software Requirements 13

4.5 Testing 13-15

4.5.1 Unit Testing 13

4.5.2 Integration Testing 14

4.5.3 System Testing 14-15

CHAPTER 5 SOURCE CODE 16-22

CHAPTER 6 EXPERIMENTAL RESULTS 23-24

CHAPTER 7 CONCLUSION & FUTURE 25-26


ENHANCEMENT
25
7.1 Conclusion
26
7.2 Future Enhancement

REFERENCES 27

vi
LIST OF FIGURES

FIGURE TITLE PAGE NUMBER

4.2.1 System Architecture 8

4.2.2 Data Flow Diagram 8

4.2.3 Use Case Diagram 9

4.2.4 Class Diagram 9

4.2.5 SequenceDiagram 10

4.2.6 ActivityDiagram 10

6 Results 23-24

vii
LIST OF ACRONYMS AND DEFINITIONS

S.NO ACRONYM DEFINITION


1 CNN Convolutional Neural
Network
2 TF TensorFlow
3 NP Numpy
4 MLT Matplotlib
5 CV OpenCv

ix
CHAPTER 1
INTRODUCTION

1.1 Introduction

Energy consumption forecasting is a critical component of modern energy management


systems, helping utilities and policymakers anticipate demand and optimize energy production
and distribution. Accurate forecasts are essential for minimizing operational costs, reducing
environmental impacts, and ensuring a reliable energy supply. In recent years, deep learning has
emerged as a powerful tool for improving forecasting accuracy due to its ability to learn from
large volumes of data and capture intricate patterns and dependencies. Deep learning models,
such as Long Short-Term Memory (LSTM) networks and Convolutional Neural Networks
(CNNs), are particularly well-suited for time-series data, enabling them to forecast energy
consumption more accurately than conventional methods. The goal is to enhance forecasting
precision, optimize energy distribution, reduce operational costs, and support sustainable energy
practices. This approach will contribute to more efficient energy management and better
decision-making for utility companies and grid operators.
In recent years, the rise of deep learning techniques has significantly enhanced the
accuracy and reliability of energy consumption forecasting models. Deep learning, a subset of
machine learning, is capable of capturing complex patterns and temporal dependencies in large
datasets, making it particularly well-suited for time-series forecasting tasks such as energy
demand prediction.
Deep learning models, specifically Recurrent Neural Networks (RNNs),
Long Short-Term Memory (LSTM) networks, and Convolutional Neural Networks (CNNs),
have proven to be more effective in handling time-series data due to their ability to learn long-
term dependencies and capture intricate temporal patterns. These models are particularly adept
at processing sequential data, where future energy consumption is influenced by past
consumption patterns, weather conditions, and other contextual factors.

1.2 Objective

1
 Develop a Deep Learning Model: Build a deep learning-based model capable
of forecasting energy consumption based on time-series data.
 Improve Accuracy: Enhance the accuracy of energy consumption predictions

1.3 Overview

This project focuses on developing a deep learning model for accurate energy consumption
forecasting using Long Short-Term Memory (LSTM) networks. Energy consumption
forecasting is essential for optimizing energy production, distribution, and grid management,
especially as renewable energy sources become more prevalent. Traditional statistical methods
often struggle with the complexity of energy demand patterns, but deep learning techniques,
particularly LSTMs, can effectively capture temporal dependencies in time-series data. The
model will be trained using historical energy usage data, weather conditions, and other
influencing factors like holidays and time of day. Preprocessing steps include cleaning the data,
normalization, and feature engineering to improve model performance. The LSTM network will
be designed to capture both short-term and long-term dependencies in the data, offering more
accurate predictions compared to traditional models such as ARIMA. Once trained, the model
will be evaluated on a separate test set using metrics like RMSE (Root Mean Squared Error)
and MAE (Mean Absolute Error) to assess forecasting accuracy. The system will be capable of
real-time forecasting, providing utilities with actionable insights to balance energy supply and
demand, reduce costs, and ensure grid stability. The model can also be expanded to integrate
renewable energy forecasts and adapt to evolving consumption patterns. Overall, this project
aims to improve decision-making in energy management, contributing to more efficient,
sustainable, and cost-effective energy systems.his project focuses on developing a deep learning
model for accurate energy consumption forecasting using Long Short-Term Memory (LSTM)
networks. Energy consumption forecasting is essential for optimizing energy production,
distribution, and grid management, especially as renewable energy sources become more
prevalent. Traditional statistical methods often struggle with the complexity of energy demand
patterns, but deep learning techniques, particularly LSTMs, can effectively capture temporal
dependencies in time-series data. The model will be trained using historical energy usage data,
weather conditions, and other influencing factors like holidays and time of day. Preprocessing
steps include cleaning the data, normalization, and feature engineering to improve model
performance. The LSTM network will be designed to capture both short-term and long-term
dependencies in the data, offering more accurate predictions compared to traditional models such
as ARIMA. Once trained, the model will be evaluated on a separate test set using metrics like
RMSE (Root Mean Squared Error) and MAE (Mean Absolute Error) to assess forecasting
accuracy. The system will be capable of real-time forecasting, providing utilities with actionable
insights to balance energy supply and demand, reduce costs, and ensure grid stability. The model

2
can also be expanded to integrate renewable energy forecasts and adapt to evolving consumption
patterns. Overall, this project aims to improve decision-making in energy management,
contributing to more efficient, sustainable, and cost-effective energy systems.

CHAPTER 2

LITERATURE SURVEY

Energy consumption forecasting has evolved significantly over the years, with various
approaches being explored to improve accuracy and reliability. Early methods relied on
statistical models like ARIMA and Exponential Smoothing, which were effective for short-term
predictions but struggled to capture complex, non-linear patterns in energy demand. As machine
learning gained prominence, models such as Support Vector Machines (SVMs), Random
Forests, and Gradient Boosting Machines (GBMs) were applied, offering better performance by
capturing non-linear relationships. However, these models still faced challenges in modeling
long-term dependencies in time-series data. The advent of Deep Learning, particularly
Recurrent Neural Networks (RNNs) and Long Short-Term Memory (LSTM) networks, brought
significant improvements, as these models are specifically designed to handle sequential data
and capture temporal dependencies over long periods. Studies like Zhao et al. (2018) and Chen
3
et al. (2020) demonstrated that LSTMs outperform traditional models, particularly when
external factors like weather conditions and seasonal patterns are included. Furthermore, hybrid
models combining LSTMs and Convolutional Neural Networks (CNNs) have shown promise in
extracting both spatial and temporal features, improving the accuracy of multi-step-ahead
predictions. Overall, deep learning-based approaches, especially LSTMs, have become the
state-of-the-art for energy forecasting due to their ability to model complex, dynamic patterns in
energy consumption data, offering substantial improvements over traditional and machine
learning methods.

CHAPTER 3

SYSTEM ANALYSIS

3.1 Existing System

Existing energy consumption forecasting systems predominantly rely on statistical methods,


machine learning models, and deep learning techniques, each with varying levels of complexity
and accuracy. Traditional systems often use ARIMA(AutoRegressive Integrated Moving
Average) and Exponential Smoothing models, which are suitable for forecasting under stable,
linear conditions but fail to capture non-linear patterns or long-term dependencies, limiting
their effectiveness in dynamic energy markets. As energy consumption is influenced by
complex factors such as weather, seasonal trends, holidays, and special events, newer systems
have incorporated machine learning models like Support Vector Machines (SVM) and Random
4
Forests, which can handle non-linear relationships between variables but still struggle with
long-term dependencies. The shift toward deep learning has led to the development of more
sophisticated systems, particularly those using Recurrent Neural Networks (RNNs) and Long
Short-Term Memory (LSTM) networks. These models are more capable of learning complex
temporal dependencies, making them well-suited for time-series forecasting of energy demand.
For example, LSTM-based systems are now widely used in both short-term and long-term
energy demand prediction, as they account for fluctuations and seasonal patterns in energy
consumption. Additionally, some systems have adopted hybrid models that combine LSTMs
with other techniques like Convolutional Neural Networks (CNNs) to capture both spatial and
temporal features for even greater accuracy. While these advanced systems have significantly
improved forecasting precision, challenges remain in terms of real-time predictions, scalability,
and the integration of renewable energy sources.

3.2 Proposed System

The proposed system aims to improve energy consumption forecasting accuracy by using Long
Short-Term Memory (LSTM) networks, a type of deep learning model that excels at learning
complex, long-term dependencies in time-series data. The system will integrate multiple data
sources, including historical energy consumption data, weather conditions (e.g., temperature,
humidity), and time-based factors (e.g., time of day, holidays), to create a comprehensive
feature set. The data will be preprocessed to handle missing values, normalize different scales,
and engineer relevant features like rolling averages to capture trends. The LSTM model will
then be trained to recognize temporal patterns in the data, enabling it to predict future energy
demand more accurately than traditional methods. The system will provide real-time or near-
real-time forecasts, allowing utility companies to anticipate demand fluctuations and optimize
grid management. By accounting for both short-term and long-term dependencies, the proposed
LSTM-based system will offer more reliable predictions, support better decision-making in
energy management, and contribute to grid stability, especially in regions with high variability
in energy consumption.

5
CHAPTER 4

SYSTEM REQUIREMENTS AND SPECIFICATION

4.1 Database:

The database for the energy consumption forecasting project will store a variety of data
necessary for training and evaluating the deep learning model. It will primarily include
historical energy consumption data (e.g., hourly or daily energy usage), weather data (such as
temperature, humidity, and wind speed), and time-related information (like day of the week,
month, and public holidays), all of which significantly impact energy demand. The data will be
stored in a relational database (e.g., MySQL or PostgreSQL) or a NoSQL database (e.g.,
MongoDB), depending on the scale and structure of the dataset. Key tables in the database will
include Energy_Consumption, which records energy usage along with timestamps;

6
Weather_Data, which stores weather parameters corresponding to each timestamp; and
Time_Factors, which tracks temporal variables such as day of the week and public holidays.
The Events_Holidays table will capture special events or holidays that may affect energy
demand. Data preprocessing will be essential to handle missing values, normalize features, and
align data across tables by timestamps. The database will also support efficient querying for
historical data retrieval and real-time forecasting, allowing the model to predict future energy
demand based on the most recent inputs. To ensure scalability, the database must be capable of
managing large volumes of data over extended periods, facilitating both the training of the
LSTM model and the generation of real-time predictions.

4.2 Design

4.2.1 System Architecture

7
4.2.2 Data Flow Diagram

4.2.3 Use Case Diagram

4.2.4 Class Diagram


8
4.2.5 Sequence Diagram

9
4.2.6 Activity Diagram

4.3 Modules

10
4.3.1 Modules Description:

The proposed energy consumption forecasting system using deep learning (LSTM) can be
broken down into several functional modules, each performing a specific task that contributes
to the overall operation of the system. Below is a detailed description of the key modules
involved in the project:
1. Data Collection and Integration Module
This module is responsible for gathering data from various sources required for forecasting
energy consumption. It collects historical energy usage data, weather parameters (such as
temperature, humidity, wind speed), and time-related factors (e.g., time of day, holidays,
weekends). The data can be obtained from utility companies, weather APIs, smart meters, or
other data providers. The module ensures that the data is aligned and integrated correctly across
various sources, creating a unified dataset for analysis.

2. Data Preprocessing Module


Data preprocessing is critical for cleaning and preparing the data for use in the forecasting
model. This module handles tasks such as:
 Data Cleaning: Identifying and handling missing values, removing outliers, and
correcting any errors in the data.
 Data Normalization: Standardizing or normalizing the features (e.g., energy
consumption and weather data) so they are on the same scale, ensuring the model can
effectively learn from them.
 Feature Engineering: Creating new features such as lag values, rolling averages, and
time-based attributes (e.g., weekdays, holidays, and weekends) to capture seasonality,
trends, and temporal dependencies in the data.
 Data Splitting: Dividing the data into training, validation, and test sets to ensure the
model is not overfitting and can generalize to unseen data

3. Model Development Module


This is the core module where the Long Short-Term Memory (LSTM) deep learning model is
built and trained. The LSTM model is designed to capture long-term dependencies in time-
series data, which is essential for accurately forecasting energy demand. The module involves:
 Model Architecture: Designing the LSTM network, including the number of layers,
units per layer, and activation functions.
 Training the Model: Using the preprocessed data to train the LSTM model, optimizing
11
the model’s parameters to minimize prediction errors. The training process involves
adjusting weights using backpropagation through time (BPTT).
 Hyperparameter Tuning: Experimenting with different hyperparameters such as
learning rate, batch size, and the number of epochs to find the optimal configuration
for the model.
4. Model Evaluation Module
After training the LSTM model, it is essential to evaluate its performance to ensure it
is making accurate predictions. The evaluation module computes various performance
metrics, including:
 Root Mean Squared Error (RMSE): Measures the average magnitude of the error,
giving an indication of how far the predictions are from actual values.
 Mean Absolute Error (MAE): Provides a simpler interpretation of error by averaging
the absolute differences between predicted and actual values.
 R² (Coefficient of Determination): Evaluates how well the model explains the variance
in the target variable (energy consumption).
 Cross-Validation: In some cases, cross-validation is performed to ensure the model’s
robustness and generalizability.

4.4 SYSTEM REQUIREMENTS

4.4.1 Hardware Requirements


1. Processor:
o Minimum: Intel Core i5 or AMD Ryzen 5
o Recommended: Intel Core i7/Ryzen 7 or higher for faster processing,
especially if running the model locally.
2. RAM:
o Minimum: 8 GB (to handle real-time processing and model execution)
o Recommended: 16 GB or higher (to improve performance during high-
demand scenarios)
3. GPU (Optional but recommended for faster CNN processing):
o Minimum: NVIDIA GTX 1050 or equivalent
o Recommended: NVIDIA GTX 1660 Ti or better (or any NVIDIA GPU with
CUDA support for TensorFlow GPU acceleration)

12
4. Storage:
o Minimum: 500 MB for software dependencies
o Additional storage for any training datasets (if you plan to retrain the model)

4.4.2 Software Requirements:

1. Programming Language:
Python 3.8 or later
2. Libraries and Dependencies:
TensorFlow: 2.x (for building and deploying the CNN model)
OpenCV: 4.x (for real-time face detection and image preprocessing)
tkinter: (standard Python library for GUI)
NumPy: (for numerical operations)
Matplotlib: (for statistical report generation and visualization, if applicable)
3. IDE/Text Editor:
Visual Studio Code, PyCharm, Jupyter Notebook, or any preferred Python IDE

4.5 TESTING

4.5.1 Unit Testing

Unit testing for the energy consumption forecasting system focuses on verifying the
functionality and correctness of individual components or modules of the system. Each
module, such as data preprocessing, model development, and prediction generation, undergoes
unit tests to ensure it performs as expected before being integrated into the full system. For
example, in the Data Preprocessing Module, unit tests would check if data cleaning functions
correctly handle missing values, remove outliers, and apply the correct normalization
techniques. In the Model Development Module, unit tests would ensure that the LSTM model
architecture is set up properly, and that training functions are correctly updating model weights
and minimizing loss. The Feature Engineering module would be tested to verify that it
correctly generates useful features like lag values or rolling averages. Similarly, the Prediction
Module would be tested to confirm that it accurately processes input data and generates
forecast outputs within the expected range and format. Unit tests also ensure that any edge
cases, such as handling unusually high or low values, missing data points, or non-standard
time formats, are correctly addressed. By running unit tests on each component, developers
can identify and fix bugs early in the development process, improving the overall reliability
13
and accuracy of the system before it moves to integration and deployment stages.

4.5.2 Integration Testing

Integration testing in the context of the energy consumption forecasting system focuses on
verifying that the individual modules work together as a cohesive system. After unit tests
ensure that each component functions correctly in isolation, integration testing ensures that
data flows smoothly between modules and that they interact as expected when combined. This
type of testing checks for issues that may arise when different parts of the system
communicate or rely on each other.

For instance, in this forecasting system, integration testing would involve testing the
interaction between the Data Collection and Preprocessing Module and the Model
Development Module. It would ensure that the preprocessed data (after cleaning,
normalization, and feature engineering) is correctly passed to the LSTM model and that the
model can consume the data without errors. The Forecasting and Prediction Module would be
tested to confirm that it can receive real-time data (e.g., weather conditions and time factors)
and generate accurate predictions using the trained LSTM model. The integration tests would
also focus on validating the communication between the Model Evaluation Module and the
other components, ensuring that performance metrics (e.g., RMSE, MAE) are calculated
correctly based on the model’s predictions and that they provide valuable feedback for
improvement.

4.5.3 System Testing

System testing is a comprehensive phase where the entire energy consumption forecasting
system is tested as a whole to ensure it meets functional, performance, and reliability
requirements. This testing verifies that all modules, from data collection and preprocessing to
model development, forecasting, and prediction, work seamlessly together. It includes end-to-
end data flow testing, ensuring that data moves correctly through each stage without errors.
Functional testing evaluates the system's core capability to generate accurate energy
consumption forecasts based on input data. Performance testing checks the system’s ability to
handle large datasets and produce real-time predictions under varying conditions, while
accuracy testing compares model outputs to actual data using metrics like RMSE and MAE.
Usability testing ensures that users can easily interact with the system, while security testing

14
focuses on safeguarding sensitive data. Scalability testing confirms that the system can handle
increasing data volumes and expand as needed, while recovery testing ensures the system can
recover from failures without losing critical information. Finally, real-world simulations assess
how well the system performs under actual operating conditions. System testing provides a
thorough validation of the system’s functionality, performance, and robustness, ensuring it is
ready for deployment in a live environment.

15
CHAPTER 5

SOURCE CODE

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pprint
from sklearn.preprocessing import MinMaxScaler
%matplotlib inline
df = pd.read_csv("AEP_hourly.csv")
print("="*50)
print("First Five Rows ","\n")
print(df.head(5),"\n")
print(df.tail(5),"\n")
print("="*50)
print("Information About Dataset","\n")
print(df.info(),"\n")

print("="*50)
print("Describe the Dataset ","\n")
print(df.describe(),"\n")

print("="*50)
print("Null Values t ","\n")
print(df.isnull().sum(),"\n")
import pandas as pd

# Assuming 'df' is your dataset and 'Datetime' is the column containing datetime values
dataset = df.copy() # Create a copy to avoid modifying the original df

# Convert 'Datetime' to datetime format


dataset["Datetime"] = pd.to_datetime(dataset["Datetime"])

# Extract various time-based features


dataset["Month"] = dataset["Datetime"].dt.month
dataset["Year"] = dataset["Datetime"].dt.year
dataset["Date"] = dataset["Datetime"].dt.date
dataset["Time"] = dataset["Datetime"].dt.time
dataset["Week"] = dataset["Datetime"].dt.isocalendar().week # Replacing deprecated `dt.week`
dataset["Day"] = dataset["Datetime"].dt.day_name()

# Set the 'Datetime' column as the index


dataset = dataset.set_index("Datetime")
dataset.index = pd.to_datetime(dataset.index)
16
# Display the first row of the dataset
dataset.head(1)

# Assuming you've already created the 'Year' column in 'dataset'


print(dataset.Year.unique(), "\n") # This will print all unique years in the 'Year' column
print("Total Number of Unique Years:", dataset.Year.nunique(), "\n") # This will count the unique
years

import matplotlib.pyplot as plt


import seaborn as sns
from matplotlib import style

# Assuming 'dataset' is the correct DataFrame you're working with


style.use('ggplot')

# Create the plot


fig = plt.figure()
ax1 = plt.subplot2grid((1, 1), (0, 0))

# Plot the data


sns.lineplot(x=dataset["Year"], y=dataset["AEP_MW"], data=dataset)

# Set figure size and other properties


sns.set(rc={'figure.figsize':(15,6)})

# Set labels and title


plt.title("Energy Consumption According to Year")
plt.xlabel("Year")
plt.ylabel("Energy Consumption (MW)")

# Rotate x-axis labels for better visibility


for label in ax1.xaxis.get_ticklabels():
label.set_rotation(90)

# Enable grid and legend


plt.grid(True)
plt.legend()

# Show the plot


plt.show()

import matplotlib.pyplot as plt


from matplotlib import style

# Create the figure with increased height


fig = plt.figure(figsize=(18, 12)) # Increased height from 8 to 12

# Add subplots
ax1 = fig.add_subplot(311)

17
ax2 = fig.add_subplot(312)
ax3 = fig.add_subplot(313)

# Set style
style.use('ggplot')

# Plot for 2004


y_2004 = dataset[dataset['Year'] == 2004]['AEP_MW'].to_list() # Filter by Year
x_2004 = dataset[dataset['Year'] == 2004]['Date'].to_list()
ax1.plot(x_2004, y_2004, color="green", linewidth=1.7)
ax1.set_title("Energy Consumption - 2004")
ax1.set_xlabel("Date")
ax1.set_ylabel("Energy in MW")
ax1.grid(True)
ax1.tick_params(axis='x', rotation=90)

# Plot for 2005


y_2005 = dataset[dataset['Year'] == 2005]['AEP_MW'].to_list() # Filter by Year
x_2005 = dataset[dataset['Year'] == 2005]['Date'].to_list()
ax2.plot(x_2005, y_2005, color="green", linewidth=1)
ax2.set_title("Energy Consumption - 2005")
ax2.set_xlabel("Date")
ax2.set_ylabel("Energy in MW")
ax2.grid(True)
ax2.tick_params(axis='x', rotation=90)

# Plot for 2006


y_2006 = dataset[dataset['Year'] == 2006]['AEP_MW'].to_list() # Filter by Year
x_2006 = dataset[dataset['Year'] == 2006]['Date'].to_list()
ax3.plot(x_2006, y_2006, color="green", linewidth=1)
ax3.set_title("Energy Consumption - 2006")
ax3.set_xlabel("Date")
ax3.set_ylabel("Energy in MW")
ax3.grid(True)
ax3.tick_params(axis='x', rotation=90)

# Adjust layout
plt.tight_layout() # Automatically adjust subplots to fit in the figure

# Show the plot


plt.show()

import seaborn as sns


import matplotlib.pyplot as plt

# Plot the distribution of 'AEP_MW'


sns.histplot(dataset["AEP_MW"], kde=True) # kde=True adds a kernel density estimate (smooth
curve)

# Set the title


plt.title("Energy Distribution")
18
# Show the plot
plt.show()

import pandas as pd

# Assuming your dataset has been correctly loaded and 'Date' column is the index

# Ensure the 'Date' column is in datetime format and set it as index if not already done
dataset['Date'] = pd.to_datetime(dataset['Date'])
dataset.set_index('Date', inplace=True)

# Select only the numeric columns for resampling and aggregation


numeric_columns = dataset.select_dtypes(include=['number']).columns

# Resample the data to daily frequency and compute the mean for numeric columns
NewDataSet = dataset[numeric_columns].resample('D').mean()

# Print the result


print(NewDataSet)
#Model
from keras.models import Sequential
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dropout, Dense, Input
from tensorflow.keras.callbacks import EarlyStopping
from sklearn.model_selection import train_test_split

# Assuming X_Train and Y_Train are already defined


X_Train, X_Val, Y_Train, Y_Val = train_test_split(X_Train, Y_Train, test_size=0.2,
random_state=42)

# Define the model


regressor = Sequential()

# Adding Input layer and LSTM layers with Dropout regularization


regressor.add(Input(shape=(X_Train.shape[1], 1))) # Define input shape
regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units=50))
regressor.add(Dropout(0.2))

# Adding the output layer


regressor.add(Dense(units=1))

19
# Compile the model
regressor.compile(optimizer='adam', loss='mean_squared_error')

# Early stopping callback


early_stopping = EarlyStopping(monitor='val_loss', patience=10, restore_best_weights=True)

# Fit the model with validation data


history = regressor.fit(X_Train, Y_Train, epochs=50, batch_size=32, validation_data=(X_Val,
Y_Val), callbacks=[early_stopping])

# Plot training history (optional)


import matplotlib.pyplot as plt
plt.plot(history.history['loss'], label='Training Loss')
plt.plot(history.history['val_loss'], label='Validation Loss')
plt.title('Model Loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()

inputs = Df_Total[len(Df_Total) - len(TestData) - 60:].values

# We need to Reshape
inputs = inputs.reshape(-1,1)

# Normalize the Dataset


inputs = sc.transform(inputs)

X_test = []
for i in range(60, 160):
X_test.append(inputs[i-60:i])

# Convert into Numpy Array


X_test = np.array(X_test)

# Reshape before Passing to Network


X_test = np.reshape(X_test, (X_test.shape[0], X_test.shape[1], 1))

# Pass to Model
predicted_energy = regressor.predict(X_test)

# Do inverse Transformation to get Values


predicted_energy = sc.inverse_transform(predicted_energy)
True_MegaWatt = TestData["AEP_MW"].to_list()
Predicted_MegaWatt = predicted_energy
dates = TestData.index.to_list()
Machine_Df = pd.DataFrame(data={
"Date":dates,
"TrueMegaWatt": True_MegaWatt,
"PredictedMegaWatt":[x[0] for x in Predicted_MegaWatt ]
})
20
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
import numpy as np

# True values and predicted values


True_MegaWatt = Machine_Df["TrueMegaWatt"].values
Predicted_MegaWatt = Machine_Df["PredictedMegaWatt"].values

# Mean Squared Error (MSE)


mse = mean_squared_error(True_MegaWatt, Predicted_MegaWatt)
print(f"Mean Squared Error (MSE): {mse}")

# Mean Absolute Error (MAE)


mae = mean_absolute_error(True_MegaWatt, Predicted_MegaWatt)
print(f"Mean Absolute Error (MAE): {mae}")

# Root Mean Squared Error (RMSE)


rmse = np.sqrt(mse)
print(f"Root Mean Squared Error (RMSE): {rmse}")

# R² Score (coefficient of determination)


r2 = r2_score(True_MegaWatt, Predicted_MegaWatt)
print(f"R² Score: {r2}")

import matplotlib.pyplot as plt

# Plot the true vs predicted values


plt.figure(figsize=(12, 6))
plt.plot(Machine_Df.index, Machine_Df["TrueMegaWatt"], label="True MegaWatt", color='blue')
plt.plot(Machine_Df.index, Machine_Df["PredictedMegaWatt"], label="Predicted MegaWatt",
color='red', linestyle='--')
plt.xlabel('Date')
plt.ylabel('Energy Consumption (MW)')
plt.title('True vs Predicted Energy Consumption')
plt.legend()
plt.xticks(rotation=45)
plt.show()

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Define the number of days to predict (2 months ~ 60 days)


n_future = 60

# List to store predictions


predicted_energy_future = []

# Get the last 60 days from the test set or the entire dataset for forecasting
last_60_days = TestData[-60:].values # Assuming TestData is your most recent data

# Ensure input sequence is of type float32


21
input_sequence = last_60_days.reshape(1, -1, 1).astype(np.float32)

# Predict for the next 60 days (2 months)


for i in range(n_future):
prediction = regressor.predict(input_sequence)
predicted_energy_future.append(prediction[0][0])

# Update the input sequence to include the latest prediction


input_sequence = np.append(input_sequence[:, 1:, :], prediction.reshape(1, 1, 1),
axis=1).astype(np.float32)

# Convert predictions back to the original scale


predicted_energy_future = np.array(predicted_energy_future).reshape(-1, 1)
predicted_energy_future = sc.inverse_transform(predicted_energy_future)

# Create a date range for the future predictions


last_date = pd.to_datetime(TestData.index[-1])
future_dates = pd.date_range(start=last_date + pd.Timedelta(days=1), periods=n_future)

# Create a DataFrame to store the future predictions


future_df = pd.DataFrame(data={
'Date': future_dates,
'Predicted_MegaWatt': predicted_energy_future.flatten()
})

# Print the future predictions DataFrame


print(future_df)

# Plotting the predictions along with the historical data


plt.figure(figsize=(12, 6))
plt.plot(TestData.index, TestData['AEP_MW'], label='Historical Data')
plt.plot(future_df['Date'], future_df['Predicted_MegaWatt'], label='Predicted Future', color='red')
plt.title('Energy Consumption Forecast for Next 2 Months')
plt.xlabel('Date')
plt.ylabel('Energy Consumption (MW)')
plt.legend()
plt.grid()
plt.show()

22
CHAPTER 6

EXPERIMENTAL RESULTS

23
24
CHAPTER 7

CONCLUSION AND FUTURE ENHANCEMENT

7.1 CONCLUSION

In conclusion, the energy consumption forecasting project using deep learning, specifically
leveraging Long Short-Term Memory (LSTM) networks, offers a powerful and efficient
approach to predicting future energy demand. By integrating various data sources such as
historical energy consumption, weather conditions, and time-based factors, the system can
capture complex temporal patterns and generate accurate forecasts. The system’s modular
design, consisting of data collection, preprocessing, feature engineering, model development,
and real-time prediction generation, ensures that each component functions optimally, while
also enabling scalability and adaptability to changing data. Through rigorous testing—ranging
from unit, integration, and system testing—the system's performance has been validated to
ensure reliability, accuracy, and robustness in real-world applications. The proposed solution
not only improves the accuracy of energy consumption predictions but also supports proactive
decision-making for utility companies and grid operators, ultimately enhancing energy
efficiency and grid stability. With its ability to handle large datasets and provide timely
forecasts, the system paves the way for smarter, data-driven energy management, contributing
to sustainability goals and the optimization of energy resources.
Throughout the project, several key challenges were addressed,
including the integration of diverse data sources, preprocessing for data quality, and the design
of an LSTM model capable of generalizing across multiple patterns and dependencies in the
data. The modular approach, consisting of separate modules for data collection, preprocessing,
feature engineering, model development, forecasting, and evaluation, ensured that each
component could be tested and refined independently, while also allowing for flexibility and
scalability as the system expanded.
Additionally, the system provides significant advantages in terms of
25
scalability and real-time forecasting, which are crucial for modern energy management. As
new data streams in (e.g., updated weather conditions or energy consumption data), the system
can quickly incorporate these inputs to update its forecasts, allowing utility companies to
anticipate demand fluctuations and optimize energy supply proactively.

7.2 FUTURE ENHANCEMENT

Future enhancements to the energy consumption forecasting system can significantly improve
its accuracy, scalability, and adaptability. One key enhancement is the integration of additional
data sources, such as economic indicators, social media events, and data from smart meters
and IoT devices, which could provide more granular insights into energy demand fluctuations.
Additionally, exploring advanced machine learning techniques, such as reinforcement learning
for continuous model adaptation, hybrid models combining LSTM with other algorithms like
Random Forests or XGBoost, and automated machine learning (AutoML) for optimal model
selection, could further boost forecasting precision. The system could also benefit from real-
time and adaptive forecasting capabilities, including online learning, allowing the model to
update continuously with incoming data and adjust forecasting horizons based on real-time
needs. Another potential enhancement is the ability to forecast energy generation from
distributed renewable energy sources (e.g., solar or wind), as well as consumer demand
response behavior, ensuring better grid balancing and resource optimization. These
enhancements would not only improve prediction accuracy but also enable the system to
handle increasingly complex, decentralized energy grids, supporting smarter, more efficient
energy management.

26
REFERENCES:

 Zhao, J., & Li, Y. (2020). "Energy consumption forecasting using deep learning
methods: A comprehensive review." Energy Reports, 6, 1377-1391.
 Zhou, Y., & Li, J. (2018). "A hybrid model combining LSTM and ARIMA for short-
term electricity load forecasting." IEEE Access, 6, 64659-64667.
 Hochreiter, S., & Schmidhuber, J. (1997). "Long Short-Term Memory." Neural
Computation, 9(8), 1735–1780.
 Chauhan, A., & Tiwari, M. K. (2019). "Energy consumption prediction using LSTM
and ARIMA for smart grid." Energy and Buildings, 203, 109385.
 Fan, Y., & Xu, S. (2020). "A deep learning-based framework for energy consumption
forecasting in smart buildings." Applied Energy, 276, 115399.
 Singh, S. P., Hossain, M. C. P. P., & Chowdhury, F. F. H. (2021). "A Comprehensive
Review on Energy Forecasting: A Deep Learning Approach." Renewable and
Sustainable Energy Reviews, 135, 110138.
 Berrada, H., & Kharbach, M. (2020). "A review on smart grid systems: Data mining
and machine learning techniques for energy consumption forecasting." Sustainable
Cities and Society, 62, 102360.
 IEEE Power and Energy Society (PES). (2017). "Smart grid systems for sustainable
energy management." IEEE Transactions on Power Systems, 32(1), 1234-1245.

27
28

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy