Keywords
anomaly detection, energy consumption, data labeling, Isolation Forest, Gaussian Naïve Bayes, energy management, machine learning techniques
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.
anomaly detection, energy consumption, data labeling, Isolation Forest, Gaussian Naïve Bayes, energy management, machine learning techniques
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.8–10 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.
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).
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:
where is the path length, which is the number of edges where point x meets the decision tree. is the expected number of , and 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 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 were used to indicate normal energy consumption while indicated anomaly energy consumption.
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:
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.
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:
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 .
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:
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.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.
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.
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:
Archived source code at time of publication: https://doi.org/10.17605/OSF.IO/CKTQS17
This project contains the following parameter code:
Data are available under the terms of the Creative Commons Attribution 4.0 International license (CC BY 4.0 Public domain dedication)
Views | Downloads | |
---|---|---|
F1000Research | - | - |
PubMed Central
Data from PMC are received and updated monthly.
|
- | - |
Is the work clearly and accurately presented and does it cite the current literature?
Partly
Is the study design appropriate and is the work technically sound?
Yes
Are sufficient details of methods and analysis provided to allow replication by others?
Yes
If applicable, is the statistical analysis and its interpretation appropriate?
Yes
Are all the source data underlying the results available to ensure full reproducibility?
Yes
Are the conclusions drawn adequately supported by the results?
Partly
References
1. Lei L, Wu B, Fang X, Chen L, et al.: A dynamic anomaly detection method of building energy consumption based on data mining technology. Energy. 2023; 263. Publisher Full TextCompeting Interests: No competing interests were disclosed.
Reviewer Expertise: Anomaly detection, Building Energy Management, AI/ML/DL
Is the work clearly and accurately presented and does it cite the current literature?
Yes
Is the study design appropriate and is the work technically sound?
Yes
Are sufficient details of methods and analysis provided to allow replication by others?
Partly
If applicable, is the statistical analysis and its interpretation appropriate?
Yes
Are all the source data underlying the results available to ensure full reproducibility?
Yes
Are the conclusions drawn adequately supported by the results?
Yes
Competing Interests: No competing interests were disclosed.
Reviewer Expertise: Machine learning
Alongside their report, reviewers assign a status to the article:
Invited Reviewers | ||
---|---|---|
1 | 2 | |
Version 1 19 Jan 22 |
read | read |
Provide sufficient details of any financial or non-financial competing interests to enable users to assess whether your comments might lead a reasonable person to question your impartiality. Consider the following examples, but note that this is not an exhaustive list:
Sign up for content alerts and receive a weekly or monthly email with all newly published articles
Already registered? Sign in
The email address should be the one you originally registered with F1000.
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.
If your email address is registered with us, we will email you instructions to reset your password.
If you think you should have received this email but it has not arrived, please check your spam filters and/or contact for further assistance.
Comments on this article Comments (0)