ALL Metrics
-
Views
-
Downloads
Get PDF
Get XML
Cite
Export
Track
Research Article

Anomalous energy consumption detection using a Naïve Bayes approach

[version 1; peer review: 2 approved with reservations]
PUBLISHED 19 Jan 2022
Author details Author details
OPEN PEER REVIEW
REVIEWER STATUS

This article is included in the Research Synergy Foundation gateway.

This article is included in the Artificial Intelligence and Machine Learning gateway.

This article is included in the Energy gateway.

Abstract

Background: Industrial energy management has emerged as an important component in monitoring energy consumption particularly with the recent trend of migrating towards IR 4.0. The capability to detect anomalies is essential as it serves as a precautionary step for real-time response to mitigate the maximum demand penalty. The purpose of this research was to develop a high accuracy anomalies detection algorithm to identify anomalies in the energy consumption data recorded by a smart meter.
Methods: The proposed algorithm utilized supervised and unsupervised machine learning techniques, namely Isolation Forest and Gaussian Naïve Bayes.  The data were first labeled by using Isolation Forest to categorize them into normal and abnormal groups. This was followed by Gaussian Naïve Bayes to classify and predict the anomalies of the smart meter reading.
Results: These machine learning techniques showed significant accuracy in predicting the anomalies in smart meter readings. The data used were simulated data collected in less than a month with 30-minute reading intervals.  The data were divided into testing and validation sets according to a ratio of 7:3. The balanced accuracy score in predicting anomalies for each different smart meter was above 89%. The average precision, average recall and average F1 score for the normal data were 98%, 99% and 98%, respectively. Whereas the corresponding scores for the abnormal data set were 95%, 90% and 92%.
Conclusions: The proposed algorithm is a hybrid approach based on Isolation Forest and Gaussian Naïve Bayes and it provided satisfactory accuracy in anomaly electricity consumption detection based on smart meter readings. The study presents a quick and simple method for categorizing energy consumption data as normal or abnormal, which assists in automatically labelling vast datasets of energy consumption readings. The proposed approach establishes a fundamental framework for predicting the occurrence of anomalies in the industrial energy management system.

Keywords

anomaly detection, energy consumption, data labeling, Isolation Forest, Gaussian Naïve Bayes, energy management, machine learning techniques

Introduction

People nowadays are continuously looking for new ways to utilize energy to improve their lives, therefore the demand for it is increasing. Most of the time, companies and industries struggle to monitor all their devices at the same time, which can lead to power wastage at any time. As a result, operational expenses will be greater than necessary. Besides that, power wastage contributes to global warming by releasing carbon when energy is generated through burning coal, gas, and oil. Hence, solutions are required to address these issues. Energy Management Information Systems (EMIS)1 or Building Energy Management Systems (BEMS)2 are the tools for continuous energy management monitoring that collect and analyze energy data on a regular basis. However, since no fixed characteristics can be retrieved, and no current static model of energy can be referred to, they give a low accuracy in predicting electricity consumption. According to an article published in Energy Malaysia,3 consumers may use the information supplied by smart meters to assist them to take prompt action in terms of power usage and waste. However, a model which is able to give early detection of deviations from historical energy usages is important and beneficial to multiple parties.

Many authors have conducted research on detecting the abnormal behavior of power usage. Yassine Himeur et al.,4 used a rule-based model to extract micro-moment features. In their method, the accuracy varied from 93.91% to 99.58% depending on the types of datasets. The main limitation of their proposed work was related to the use of supervised learning in training the classifier. Wenqiang Cui and Hao Wang5 proposed a hybrid model that combines polynomial regression and Gaussian distribution to detect the anomalies of data. They focused on school power consumption and were able to detect anomalies with 0 false-negative and an average precision higher than 91%. However, the model must be trained manually. Ma and Zhang6 developed a method to detect abnormal building energy consumption in real time. They used fractal correlation dimension (FCD) and proper orthogonal decomposition linear stochastic estimation (POD-LSE). They claimed that the performance of the method depended on the threshold selected. Thus, improvement was required by integrating with other intelligent algorithms. Jecinta Mulongo et al.,7 used support vector machines (SVM), K-Nearest Neighbors (KNN), Logistic Regression (LR), and MultiLayer Perceptron (MLP) to detect anomalies in power generation plant data. They reported that MLP has the best performance in the evaluation measurement with a score of 96% in the K-fold cross validation test. In addition, deep learning has also received increasing interest for abnormality detection.810 Besides using machine learning and deep learning to detect anomaly electricity consumption, statistical techniques are used to monitor the consumption pattern. For example, Lin and Claridge11 used the deviation between collected and simulated energy usage and also the standard deviation of the residuals to detect the abnormal consumption. The limitation here was that only limited assumed cases were used. Araya et al.,12 used sliding window framework to capture contextual characteristics and historical sensor data in detecting the anomalous pattern. Liu et al.,13 proposed a statistical-based online detection technique with a Lambda scheme, which involved an in-memory distributed computing algorithm. Chen et al.14 also proposed a statistical predictive method utilizing mean and variance in detecting the energy anomalies.

One of the challenges that complicates the development of anomaly detection technique is the absence of labelled ground-truth datasets. There is a lack of research addressing how to classify energy consumption readings as normal or abnormal, as well as the nature of the abnormality.15 Additionally, as data on electricity consumption continues to expand tremendously, the properties of big data become more apparent, which further complicates the process of detecting anomalies. To that end, this paper proposes a method for detecting anomalies in energy consumption readings using an unsupervised approach that combines Isolation Forest and Naive Bayes models. The Isolation Forest is shown to be capable of detecting not only point anomalies with peaks, but also contextual anomalies. Whereas, when combined with Naive Bayes, the possibility of performing anomaly detection without retraining the data is demonstrated. This hybrid approach to labeling energy consumption readings demonstrates a straightforward and efficient method for assisting in the energy consumption readings labeling, which is critical in today's rapidly growing data volume era.

In this paper, a two-stage anomalous detection model is proposed to detect any anomalies of smart meter readings. This paper is organized as follows: Section 1 is the introduction, section 2 describes the methodology, which includes data labelling and the detection model. Section 3 presents the results and discussion. Finally, we conclude the research and introduce future work in Section 4.

Methods

The anomalous detection model is built in two stages. The first stage focuses on utilizing the Isolation Forest in labeling the energy consumption data into two categories: normal consumption or abnormal peak. In the second stage, the energy consumption data as well as the corresponding labelled categories are then used to train a detection model using the Gaussian Naïve Bayes approach. The trained model can then be used to detect any anomalous unseen energy consumption data. The proposed model is implemented using the Python programming language, version 3.7 (RRID:SCR_008394).

Stage 1: Data labeling with Isolation Forest

Isolation Forest is one of the unsupervised machine learning algorithms used to detect anomalies in a dataset. Unlike supervised machine learning algorithms, Isolation Forest does not require any label or classification for the data to be analyzed. The algorithm isolates or separates anomalies by considering anomalies as instances that are less likely to occur or attribute values that are very different from normally attributed values. For Isolation Forest, the anomaly score is calculated with the equation below:

sxn=2Ehxcn
where hxis the path length, which is the number of edges where point x meets the decision tree. Ehx is the expected number of hx, and cn is the average path length of the total decision tree. From the equation, when the path length is low, an isolated point, the value for Ehx is close to zero and the score is close to 1. When the total path length is equal to the average path length the score will be 0.5. According to Liu et al.,16 the potential anomalies can be acknowledged as an anomaly score above 0.6.

Figure 1 gives the labelling flow chart using Isolation Forest. The unlabeled data was first imported into the Jupyter Notebook (Jupyter Notebook, RRID:SCR_018315). The Isolation Forest from sklearn.ensemble was then used to identify the anomaly scores. In our work, the anomaly scores above 0.53 were classified as abnormal data. The classified values of C0=0 were used to indicate normal energy consumption while C1=1 indicated anomaly energy consumption.

fe838a56-dc4e-4610-92a7-3e4017647413_figure1.gif

Figure 1. Flow chart of stage 1 data labeling with Isolation Forest.

Stage 2: Detection model based on Gaussian Naïve Bayes

The Gaussian Naïve Bayes is one of the most popular classifier algorithms in data mining and the data science field. It is well known since it is a simple technique for deciphering binary or categorical input values, and it does not necessitate a large amount of data for training. Since the energy consumption data is in a continuous form, the Gaussian Naïve Bayes that follows a Gaussian normal distribution was chosen to build the detection model. In general, Gaussian Naïve Bayes calculates the probability density of v for certain data to be assigned to respective classes according to the equation:

(1)
px=vCk=12πσk2evμk22σk2
with x is the energy consumption, Ck is the data labelling, μkis the mean of the values in x associated with Ck, σk is the Bessel corrected variance of the values in x associated with class Ck. Thus, given an unseen energy consumption value x, its probabilities of being classified into an abnormal class will be calculated based on the well-known Bayesian Theorem:
(2)
pC1x=pxC1pC1px=pxC1pC1i=0,1pxCipCi
with the probabilities px=vCk can be obtained from equation (1). If pC1x is greater than 0.5, then the point would be classified as abnormal, else it would be classified as a normal energy consumption point. The trained Naïve Bayes model can then be used to classify the unseen energy consumption reading into normal and abnormal. The proposed anomalous detection model was verified using simulated smart meter readings with each reading for a smart meter collected in 30-minute intervals for a period of 576 hours. Firstly, the pattern of the electricity data of the Irish Social Science Data Archive (ISSDA) were investigated. Next, three sets of smart readings were generated based on different values of peak-to-peak and valley-to-valley intervals. Then, the energy consumption values were manually created based on assumption of different users’ behavior.17

Results

Three smart meter readings were simulated in the analysis, namely smart meter ID A, smart meter ID B and smart meter ID C. The energy curves of each of these meter readings exhibited varied behavior and their respective energy consumption profiles are depicted in Figure 2. Most of the spikes in the energy curve of smart meter ID A are of similar height. However, the peak values of the energy curve in smart meter ID B are more variable. Meanwhile, the energy curve of smart meter ID C is flatter.

fe838a56-dc4e-4610-92a7-3e4017647413_figure2.gif

Figure 2. Energy curves of simulated energy consumption data and spikes labeled as abnormal: (a) smart meter A (b) smart meter B (c) smart meter C.

To ensure that the verification process was performed without bias, the data was categorized in a 70:30 ratio, with 70% of data utilized for training, and 30% of data reserved for verification as unseen data to the training model. The performance of the anomalous detection model was evaluated using the following formulae on precision, recall and F1 score:

precision=TPTP+FP
recall=TPTP+FN
F1score=2precisionrecallprecision+recall

TP, FP and FN refer to true positive, false positive and false negative, respectively.

Take the case when positive (P) refers to the anomalous point, for example, then TP denotes that the abnormal points are accurately identified as abnormal, whereas FP denotes that the normal points are incorrectly detected as abnormal by the model. Finally, abnormal points detected as normal by the model are referred to as FN. Therefore, the precision gives the proportion of detected anomalous points that are actually abnormal. The counterpart of precision is recall, which refers to the ability to recognize abnormal points among the actual abnormal points. F1 score combines precision and recall and calculates the harmonic mean. The F1 score reaches its optimum value of 1 if both precision and recall are both at 100%.

Table 1 summarizes the above scores for smart meter ID A, smart meter ID B and smart meter ID C. The calculations were performed for two cases when the positive, P = 0 and when the positive, P = 1 .

Table 1. Performance scores of anomalous detection model for different smart meters.

Smart meter ID
ABCAverage
Normal (when P = 0)Precision1.000.980.960.98
Recall0.971.001.000.99
F1 score0.980.990.980.98
Abnormal (when P = 1)Precision0.851.001.000.95
Recall1.000.920.790.90
F1 score0.920.960.880.92

The time series dataset involved is known to have issues of imbalanced data, with a large portion of the data considered normal consumption. The performance of the proposed model is further evaluated by balanced accuracy, a well-known metric for imbalanced data. The balanced accuracy is given as:

balanced accuracy=12TPP+TNN,
which is the average of true positive rate and true negative rate. Table 2 provides the calculated balanced accuracy score for 3 different smart meters.

Table 2. Balanced accuracy score of the anomalous detection model for different smart meters.

Smart meter IDBalanced accuracy score
A0.9827
B0.9576
C0.8947

Discussion

In the performed simulation, labeling based on Isolation Forest was performed to the given time series data to identify the anomalous instances. The red dots associated with the peaks of the energy profiles in Figure 2 refer to the identified anomalous points. It can be observed that the Isolation Forest approach was able to detect almost all the local maximum points, which coincided with the instances of peaks in the energy consumption profiles. This tallied with the requirement of anomalous energy detection, as the spikes are not merely tied to the magnitude in kW, but mainly depend on the behavior of the profile in its neighborhood. Thereby, Isolation Forest is able to capture the peak regardless of the pattern exhibits in the dataset. Despite the fact that the peak’s value is low in comparison to the rest of the overall dataset, it is still an atypical peak when compared to surrounding past measurements that are lower. Based on the simulation results, we can observe that Isolation Forest is a suitable strategy for auto labeling the smart meter readings. The approach is relatively direct to implement when compared to alternative approaches that define or predict the anomalies based on absolute magnitude analysis with mean and variance.15 Isolation Forest is especially valuable if the user’s behavior changes with the seasons, such as when the energy readings are high during high production periods but low during low production periods. In summary, Isolation Forest is capable not only in detecting the point anomalies, but also in detecting the peak anomalies in contextual perspectives. However, if using Isolation Forest to classify anomalies requires processing an entire series of data in a specific window, this may not be feasible given the rapid growth of electricity consumption data. To that end, the Isolation Forest-labeled data is used to train a Naive Bayes model, which enables rapid classification of a single piece of data into normal or abnormal states without requiring previous points to be processed batch-wise as in Isolation Forest. For both classification results by Naïve Bayes model, the precision scores obtained for all smart meters were above 0.85, the recall values were above 0.79 and the F1 scores were above 0.88. The recall value of smart meter ID C for P = 1 was 0.79, which was the lowest score of all. This indicates that the model could only recognize 79% of the actual anomalous data, which could be related to the flattening trend of the energy consumption profiles, making it more difficult and challenging to identify spikes. In general, the performance of the anomalous detection models was satisfactory. The average F1 score was 0.98 and 0.92, for normal and abnormal data, respectively. This indicates that the model has harmonic high performance for both precision and recall. The time series dataset involved is known to have the issues of imbalanced data, with a large portion of the data considered normal consumptions. The balanced accuracy score for all smart meters was above 0.8947. Therefore, the proposed anomalous detection model not only detects the anomalous points successfully, but also classifies the normal points appropriately.

Conclusions

This paper proposed a two-stage anomalous detection model, combining the Isolation Forest and Gaussian Naïve Bayes. The performed simulations showed that a balanced accuracy score of at least 0.8947 was achieved. The Isolation Forest approach was used to label normal and abnormal data, and it successfully identified the abnormal spikes based on the behavior of the energy consumption pattern rather than just the magnitude of consumption. In detecting anomalies, the Gaussian Naïve Bayes gave a satisfactory performance in detecting the abnormal points as well as the normal points. The proposed approach combining Isolation Forest and Naive Bayes can be used to detect anomalies in a given time series of energy consumption. In comparison to using only the Isolation Forest for classification, this hybrid approach provides a straightforward method for labelling the data, which is particularly useful when the data set is large and arrives in batches. Classification does not have to be repeated using Isolation Forest and all available data; rather, once trained, the trained Naive Bayes model can classify effectively. However, the size of the current simulation was limited by the available dataset. A larger amount of data should be collected and applied to this model in the future. Furthermore, the optimum dataset size to achieve high accuracy also needs to be identified.

Data availability

Underlying data

Open Science Framework. Underlying data for ‘Anomalous energy consumption detection using a Naïve Bayes approach’, https://doi.org/10.17605/OSF.IO/CKTQS17

This project contains the following underlying data:

  • Smart meter data.xlsx

Software availability

Archived source code at time of publication: https://doi.org/10.17605/OSF.IO/CKTQS17

This project contains the following parameter code:

  • Model A GNB.ipynb

  • Model B GNB.ipynb

  • Model C GNB.ipynb

Data are available under the terms of the Creative Commons Attribution 4.0 International license (CC BY 4.0 Public domain dedication)

Comments on this article Comments (0)

Version 1
VERSION 1 PUBLISHED 19 Jan 2022
Comment
Author details Author details
Competing interests
Grant information
Copyright
Download
 
Export To
metrics
Views Downloads
F1000Research - -
PubMed Central
Data from PMC are received and updated monthly.
- -
Citations
CITE
how to cite this article
Lim JY, Tan WN and Tan YF. Anomalous energy consumption detection using a Naïve Bayes approach [version 1; peer review: 2 approved with reservations]. F1000Research 2022, 11:64 (https://doi.org/10.12688/f1000research.70658.1)
NOTE: If applicable, it is important to ensure the information in square brackets after the title is included in all citations of this article.
track
receive updates on this article
Track an article to receive email alerts on any updates to this article.

Open Peer Review

Current Reviewer Status: ?
Key to Reviewer Statuses VIEW
ApprovedThe paper is scientifically sound in its current form and only minor, if any, improvements are suggested
Approved with reservations A number of small changes, sometimes more significant revisions are required to address specific details and improve the papers academic merit.
Not approvedFundamental flaws in the paper seriously undermine the findings and conclusions
Version 1
VERSION 1
PUBLISHED 19 Jan 2022
Views
3
Cite
Reviewer Report 15 Jun 2023
Yassine Himeur, University of Dubai, Dubai, Dubai, United Arab Emirates 
Approved with Reservations
VIEWS 3
This research aimed to create an accurate anomaly detection algorithm for industrial energy consumption, leveraging IR 4.0 trends. The algorithm uses a hybrid approach of Isolation Forest and Gaussian Naïve Bayes machine learning techniques, categorizing smart meter readings into normal ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Himeur Y. Reviewer Report For: Anomalous energy consumption detection using a Naïve Bayes approach [version 1; peer review: 2 approved with reservations]. F1000Research 2022, 11:64 (https://doi.org/10.5256/f1000research.74260.r177529)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.
Views
9
Cite
Reviewer Report 16 Feb 2022
Kim Gaik Tay, Faculty of Electrical and Electronic Engineering, Universiti Tun Hussein Onn Malaysia, Batu Pahat, Malaysia 
Approved with Reservations
VIEWS 9
This paper demonstrates the use of unsupervised machine learning techniques by Isolation Forest to label normal and anomalous points of energy consumption, as well as a Gaussian supervised method, namely Naïve Bayes, to classify the normal and anomalous points of ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Tay KG. Reviewer Report For: Anomalous energy consumption detection using a Naïve Bayes approach [version 1; peer review: 2 approved with reservations]. F1000Research 2022, 11:64 (https://doi.org/10.5256/f1000research.74260.r120393)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.

Comments on this article Comments (0)

Version 1
VERSION 1 PUBLISHED 19 Jan 2022
Comment
Alongside their report, reviewers assign a status to the article:
Approved - the paper is scientifically sound in its current form and only minor, if any, improvements are suggested
Approved with reservations - A number of small changes, sometimes more significant revisions are required to address specific details and improve the papers academic merit.
Not approved - fundamental flaws in the paper seriously undermine the findings and conclusions
Sign In
If you've forgotten your password, please enter your email address below and we'll send you instructions on how to reset your password.

The email address should be the one you originally registered with F1000.

Email address not valid, please try again

You registered with F1000 via Google, so we cannot reset your password.

To sign in, please click here.

If you still need help with your Google account password, please click here.

You registered with F1000 via Facebook, so we cannot reset your password.

To sign in, please click here.

If you still need help with your Facebook account password, please click here.

Code not correct, please try again
Email us for further assistance.
Server error, please try again.