=Paper= {{Paper |id=Vol-3375/paper8 |storemode=property |title=Time Series Anomaly Detection in Smart Homes: A Deep Learning Approach |pdfUrl=https://ceur-ws.org/Vol-3375/paper8.pdf |volume=Vol-3375 |authors=Somayeh Zamani,Hamed Talebi,Gunnar Stevens |dblpUrl=https://dblp.org/rec/conf/amlts/ZamaniTS22 }} ==Time Series Anomaly Detection in Smart Homes: A Deep Learning Approach== https://ceur-ws.org/Vol-3375/paper8.pdf
Time Series Anomaly Detection in Smart Homes: A Deep
Learning Approach
Somayeh Zamani1,* , Hamed Talebi2 and Gunnar Stevens1
1
    University of Siegen, Siegen, Germany
2
    Amirkabir University of Technology, Tehran, Iran


                                           Abstract
                                           Fixing energy leakage caused by different anomalies can result in significant energy savings and extended appliance life.
                                           Further, it assists grid operators in scheduling their resources to meet the actual needs of end users, while helping end users
                                           reduce their energy costs. In this paper, we analyze the patterns pertaining to the power consumption of dishwashers used in
                                           two houses of the REFIT dataset. Then two autoencoder (AE) architectures with 1D-CNN and TCN as backbones are trained
                                           to differentiate the normal patterns from the abnormal ones. Our results indicate that TCN outperforms CNN1D in detecting
                                           anomalies in energy consumption. Finally, the data from the Fridge_Freezer and the Freezer of house No. 3 in REFIT is also
                                           used to evaluate our approach.

                                           Keywords
                                           Time series, Anomaly detection, Deep learning, Autoencoder, Temporal convolutional networks, Smart home, Sustainability



1. Introduction                                                                                              higher power consumption or damage in the most critical
                                                                                                             cases [8].
Throughout recent years, the energy demand has signifi-                                                         Thus, for optimization purposes in smart homes, via
cantly gone up due to urban and industrial development                                                       implementing load monitoring systems and formulating
alongside an increase in population [1]. Therefore, cli-                                                     smart anomaly detection models using machine learning
mate change, global warming, and volatility in energy                                                        techniques, the abnormality can be mitigated [9]. To do
prices have fuelled the interest in smart systems [2]. In                                                    so, it is essential to analyze the energy consumption of
this regard, the huge potential increase of replacing tra-                                                   households in order to identify consumption patterns and
ditional home appliances with new in-operation power-                                                        extract valuable information from smart homes [8][10].
consuming ones by 2040 has caused the residential sector                                                        In this paper, the power consumption patterns of dish-
to account for roughly 60% over 2017-25 and 70% over                                                         washers used in houses No. 1 and 2 of the REFIT dataset
2025-40 of electricity demand increase of buildings. As                                                      are analyzed as examples of devices that are used based
such, household appliances need to be operating effi-                                                        on the needs of users. Then, the data for each usage of
ciently and used appropriately to achieve energy-saving                                                      the device is divided into different signals to properly
goals [3].                                                                                                   train autoencoders with different backbones, including
   To this end, utilizing AI-based technologies and smart                                                    1-dimensional CNN and TCN, to detect abnormal usage.
homes as novel interventions to recognize abnormal                                                           For this purpose, any predicted value that is greater than
power utilization and understand the reasons for each ab-                                                    twice the standard deviation of the electricity consump-
normality could pave the way for end-consumers both to                                                       tion the day before is considered abnormal.
renovate wasteful devices and adopt a more sustainable                                                          The rest of the paper is organized as follows. We pro-
energy consumption behavior [4][5][6][7]. Moreover, it                                                       vide related work on anomaly detection in energy con-
facilitates the prediction of end-users power demand as                                                      sumption in Section 2. In Section 3, our methodology is
well as performing an optimal energy distribution by                                                         presented in details. Section 4 concludes the paper and
grid operators depending on specific end-users’ needs.                                                       discusses future work.
In addition, electrical anomalies are less likely to remain
unnoticed for a long period of time which would result in
                                                                                                             2. Related work
AMLTS’22: Workshop on Applied Machine Learning Methods for Time
Series Forecasting, co-located with the 31st ACM International Con-                                                                 In the context of energy usage, anomalies are defined as
ference on Information and Knowledge Management (CIKM), October
                                                                                                                                    deviations from expected behavior that occur when the
17-21, 2022, Atlanta, USA
*
  Corresponding author.                                                                                                             consumption of a household appliance does not corre-
$ somayeh.zamani@uni-siegen.de (S. Zamani);                                                                                         spond with its normal pattern [3][11]. Among the key
hamed.talebi.aut@gmail.com (H. Talebi);                                                                                             applications of anomaly detection by load monitoring,
gunnar.stevens@uni-siegen.de (G. Stevens)                                                                                           are forecasting maintenance and energy efficiency [12].
                                       Β© 2022 Copyright for this paper by its authors. Use permitted under Creative Commons License
                                       Attribution 4.0 International (CC BY 4.0).                                                   Thus, a smart plug, smart appliance, and other appliance-
    CEUR
    Workshop
    Proceedings
                  http://ceur-ws.org
                  ISSN 1613-0073
                                       CEUR Workshop Proceedings (CEUR-WS.org)
                                                           method, the feature representations are enforced to learn
                                                           important regularities of the data so that reconstruction
                                                           errors are minimized. Consequently, anomalies are dif-
                                                           ficult to reconstruct from the resulting representations
                                                           and are, therefore, subject to large reconstruction errors
                                                           [17].


                                                           3. Methodology
                                                           3.1. Dataset and preprocessing
                                                           The REFIT Electrical Load Measurements dataset con-
                                                           tain cleaned electrical consumption data in Watts for 20
                                                           households in the UK at both the aggregate and appli-
Figure 1: The architecture of the CNN-based autoencoder ance level. The data is related to a period of two years
(CNN-AE)                                                   comprising nine individual appliance measurements at
                                                           8-second intervals per house with 1,194,958,790 readings
                                                           [16]. The models proposed in this paper are trained using
level monitoring devices are needed to continuously mon- dishwasher data from houses No. 1 and 2. Furthermore,
itor the power consumption of individual appliances in data from the Fridge_Freezer and the Freezer of house
a house [8]. However, identifying anomalies, and their No. 3 is used to assess the effectiveness of our approach.
nature of them should also be considered, which can be        To begin with, it is necessary to resample the data
categorized, based on different dimensions. In the data to convert it into equal time intervals r. Then using
science world, anomalies are seen as either single points the following formula, the average sampling time, 𝑑 of
that are not necessarily relevant to each other or a set the REFIT data is used to fill in a limited number of
of data points that constitute a pattern and, therefore, signals, n with no data. The remaining empty intervals
can be interpreted in relation to each other. The other are substituted with zero.
dimension of anomaly detection that should be taken
                                                                                      [οΈ‚     ]οΈ‚
                                                                                         4*𝑑
into account is the context which refers to a deviation in                        𝑛=                              (1)
                                                                                          π‘Ÿ
a particular context relating to the structure of the data
[3][13][14]. For example, in the context of a warm sea- Additionally, for devices used according to users’ needs,
son, a temperature report of -30 degrees Celsius can be consumption data must first be differentiated. The power
anomalous; however, during a cold season, such a report consumption pattern may include turning the device on
may be more common [3]. To this end, understanding and off several times per usage. The matching data is
the available data will provide a solid foundation for im- therefore combined into relevant signals. Also, due to
proving energy efficiency. For this purpose, there are the possibility of failure in some devices that can result
thirty-one publicly available databases with several fea- in constant operation for an extended period, we assume
tures, such as the geographical location, period of col- a maximum period for a device to operate.
lection, number of monitored households, the sampling
rate of collected data, and number of sub-metered appli-
ances [15]. Regarding this, a valuable dataset is REFIT
which includes cleaned electrical consumption in Watts
for 20 households in the UK at both the aggregate and
appliance levels [16]. On the other hand, Pang [11] has
provided a comprehensive overview of current anomaly
detection methods to gain an important understanding of
their inherent capabilities and limitations in addressing
some largely unsolved challenges in anomaly detection. Figure 2: The architecture of the TCN-based autoencoder
According to his study, Autoencoders, which are a sub- (TCN-AE)
set of the generic normality feature learning category,
aim to learn some low-dimensional feature representa-
tion space on which the given data instances can be well 3.2. The proposed models
reconstructed. While this is a widely used method for
data compression or dimension reduction, by using this The development of time series anomaly detection al-
                                                           gorithms has recently received considerable attention.
Autoencoder-based approaches are often used to identify          by a factor of 𝑠. To do so, groups of size 𝑠 are averaged
anomalous behavior by analyzing the reconstruction er-           along the time axis.
ror of the data [18][19][20]. Having learned a nonlinear            In the decoder module, the downsampled sequence
transformation of the input data into a compressed rep-          is returned to its original length by performing a near-
resentation, latent variables are used to reconstruct the        est neighbor interpolation on the upsampled sequence.
original input. On the other hand, utilizing the convolu-        Upsampled sequences are passed through a second TCN
tion mechanism in sequential models is computationally           with independent weights parameterized similarly to the
optimal [21]. Also, due to CNNs’ equivariance proper-            encoder-TCN. As a final step, the input sequence is re-
ties and sparse interactions, they are translated from           constructed with a Conv1D layer that ensures that the
computer vision into the time domain using temporal              dimensionality of the input is matched (by setting π‘˜ = 1
convolutional networks (TCN)[20].                                and 𝑛𝑓 π‘–π‘™π‘‘π‘’π‘Ÿπ‘  = 𝑑) [20]. As described in the next section,
   In the following sections, we will describe how we            the input sequence and its reconstruction will be used
used autoencoders (AEs) for time series data that utilize        for detecting anomalies after TCN-AE has been trained.
1-dimensional CNNs and TCNs as building blocks to
detect energy anomalies in the REFIT dataset.

3.2.1. CNN-based autoencoder (CNN-AE)
We used TensorFlow to implement the architecture con-
sisting of two smaller sequential models, an encoder and
a decoder. Also, considering the speed of the model con-
vergence, our CNN-based autoencoder is comprised of
3 layers of Conv1D using the data of the households’
dishwashers. Furthermore, a nonlinear ReLu activation
function is used in each convolution layer. In this model,
a standard rate of 0.2 is considered for the dropout layer
to randomly remove 20% of the upper layer during learn-
ing.
   Figure 1. shows the layers and the number of input and
output parameters of each. The input layer is 320 Γ— 1 Figure 3: (a) Examples of the normal energy consumption
(3200 seconds), calculated according to the maximum of the dishwasher (b) Examples of the abnormal energy con-
operation time of the device.                              sumption of the dishwasher


3.2.2. TCN-based autoencoder (TCN-AE)
The temporal convolutional network (TCN) combines                3.3. Experimental results
simplicity with auto-regressive prediction, residual             3.3.1. Anomaly detection
blocks, and a very long memory. In general, a TCN can
be broken down into three components: a list of dilation         We compute a threshold value of 2𝜎 above the predicted
rates 𝐷 = {π‘ž1 , π‘ž2 , ..., π‘žπ‘›π‘Ÿ }, the number of 𝑛𝑓 π‘–π‘™π‘‘π‘’π‘Ÿπ‘  , and   value to measure the trend in electricity consumption
the kernel size π‘˜, which is the same for all filters in a TCN    over time, where 2𝜎 is the standard deviation on the
[20][22]. Inspired by a classical (deep) autoencoder, the        day before the actual moment [23]. An abnormal state is
TCN autoencoder encodes sequences, along the temporal            defined as a value exceeding the threshold for predicted
axis, of length 𝑇 into a compressed representation of            electricity consumption at the actual moment. Equations
length 𝑇 /𝑠 (where 𝑠 ∈ Z+ ) and then tries to reconstruct        (2) and (3) show the calculation of 𝜎 and π›Ύπ‘‘β„Žπ‘Ÿπ‘’π‘ β„Žπ‘œπ‘™π‘‘ :
the original sequence[20].                                                            βˆšοΈ‚ βˆ‘οΈ€π‘›
                                                                                            𝑖=1 (π‘₯𝑖 βˆ’ π‘₯)
                                                                                                         2
   In Figure 2, each layer of the TCN-AE is described                             𝜎=                                    (2)
by its parameters within the box. TCN-AE receives a                                              𝑛
sequence π‘₯[𝑛] of length 𝑇 and dimensionality 𝑑 as its                              π›Ύπ‘‘β„Žπ‘Ÿπ‘’π‘ β„Žπ‘œπ‘™π‘‘ = 𝛾
                                                                                                Μ‚οΈ€ + 2𝜎                  (3)
input. Using a TCN, the encoder first processes input
sequence π‘₯[𝑛] of length 𝑇 and dimension 𝑑. Afterward, a          where 𝜎 is the standard deviation, π›Ύπ‘‘β„Žπ‘Ÿπ‘’π‘ β„Žπ‘œπ‘™π‘‘ is the
one-dimensional convolutional layer with π‘ž = 1, π‘˜ = 1,           threshold, 𝛾
                                                                            Μ‚οΈ€ is the predicted value, π‘₯𝑖 is the electricity
and 𝑛𝑓 π‘–π‘™π‘‘π‘’π‘Ÿπ‘  = 8 is used to reduce the dimensionality of        consumption, π‘₯ is the average electricity consumption,
the TCN’s output. As the last layer in the encoder, the          and 𝑛 is the number of samples.
temporal average pooling layer downsamples the series               A normal electricity usage pattern detection for the
                                                                 dishwasher is shown in Figure 3 (a), where the real-time
Table 1
Evaluation of CNN1D-AE performance with a different data division ratio

                                      Model       Division Ratio    MAE       MAPE
                                    CNN1D-AE            9:1         0.1781    %22.55
                                    CNN1D-AE            8:2         0.1570    %20.07
                                    CNN1D-AE            7:3         0.1702    %21.99


Table 2
Evaluation of TCN-AE performance with a different data division ratio

                                      Model      Division Ratio    MAE       MAPE
                                     TCN-AE           9:1          0.1527    %21.39
                                     TCN-AE           8:2          0.1371    %17.52
                                     TCN-AE           7:3          0.1412    %19.88



threshold curve follows the sequence trend, indicating        tection techniques, abnormal behaviors can be mitigated.
the model depicts the dishwasher’s normal electricity us-     This is possible, especially if user-centric explainable
age. As can be seen in the figure, the real power consump-    recommender systems are combined with anomaly de-
tion curve does not exceed the threshold range, which         tection modules. However, there is no proper labeled
indicates a normal level of electricity consumption. As       dataset available to develop accurate algorithms or de-
shown in Figure 3 (b), anomalous consumption patterns         tect different types of anomalies. Accordingly, we plan to
occur when actual values exceed the threshold. Conse-         run a laboratory to build the first appropriately labeled
quently, the method can distinguish between normal and        energy anomaly dataset.
abnormal consumption behavior.

3.3.2. Evaluation
                                                              Acknowledgments
As Table 1. and Table 2. show, for both architectures, the This research has been funded by the EU Horizon 2020
best performance is obtained with the data division ratio Marie SkΕ‚odowska-Curie International Training Network
of 8:2, and clearly, TCN-AE is more efficient than CNN- GECKO, Grant number 955422.
AE. Our unsupervised approach has also been evaluated
using the data from the Fridge_Freezer and the Freezer
of house No. 3 in REFIT. The results in Table 3. confirm
                                                            References
the best division ratio of 8:2 and the higher performance   [1] M. Pothitou, A. J. Kolios, L. Varga, S. Gu, A
of TCN compared to CNN1D.                                        framework for targeting household energy savings
                                                                 through habitual behavioural change, International
4. Conclusion and future work                                    Journal of Sustainable Energy 35 (2016) 686–700.
                                                            [2] D. Marikyan, S. Papagiannidis, E. Alamanos, A
This paper presents the starting point of our work on            systematic review of the smart home literature: A
studying how would applying deep learning algorithms,            user perspective, Technological Forecasting and
and explainability improve energy efficiency, environ-           Social Change 138 (2019) 139–154.
mental sustainability, and user adoption. In this regard, [3] S. S. Hosseini, K. Agbossou, S. Kelouwani, A. Carde-
first, we preprocessed our data by resampling and differ-        nas, N. Henao, A practical approach to residential
entiating each usage. Next, the extracted patterns of dish-      appliances on-line anomaly detection: A case study
washer usage in houses No. 1 and 2 of the REFIT dataset          of standard and smart refrigerators, IEEE Access 8
were analyzed. Two deep learning models, CNN-AE and             (2020)  57905–57922.
TCN-AE were then trained to detect abnormalities. While     [4] T. Schwartz, S. Denef, G. Stevens, L. Ramirez,
the TCN backbone performed better, we evaluated our             V. Wulf, Cultivating energy literacy: results from a
models using the data from the refrigerators of house No.        longitudinal living lab study of a home energy man-
3 in REFIT as well.                                              agement system, in: Proceedings of the SIGCHI
   Through the implementation of energy monitoring               Conference on Human Factors in Computing Sys-
systems and the formulation of intelligent anomaly de-           tems, 2013, pp. 1193–1202.
Table 3
Evaluation of the model’s performance using the Fridge_Freezer and the Freezer data of house #3

                                      Model       Division Ratio    MAE      MAPE
                                    CNN1D-AE           9:1         0.1678    %21.15
                                    CNN1D-AE           8:2         0.1486    %19.17
                                    CNN1D-AE           7:3         0.1649    %20.29
                                     TCN-AE            9:1         0.1422    %18.21
                                     TCN-AE            8:2         0.1264    %16.33
                                     TCN-AE            7:3         0.1353    %17.70



 [5] Y. Himeur, K. Ghanem, A. Alsalemi, F. Bensaali,          [16] D. Murray, L. Stankovic, V. Stankovic, An electri-
     A. Amira, Artificial intelligence based anomaly               cal load measurements dataset of United Kingdom
     detection of energy consumption in buildings: A re-           households from a two-year longitudinal study, Sci-
     view, current trends and new perspectives, Applied            entific data 4 (2017) 1–12.
     Energy 287 (2021) 116601.                                [17] M. Hasan, J. Choi, J. Neumann, A. K. Roy-
 [6] S. Chen, T. Liu, F. Gao, J. Ji, Z. Xu, B. Qian, H. Wu,        Chowdhury, L. S. Davis, Learning temporal reg-
     X. Guan, Butler, not servant: A human-centric                 ularity in video sequences, in: Proceedings of the
     smart home energy management system, IEEE                     IEEE conference on computer vision and pattern
     Communications Magazine 55 (2017) 27–33.                      recognition, 2016, pp. 733–742.
 [7] B. Zhou, W. Li, K. W. Chan, Y. Cao, Y. Kuang,            [18] S. Hawkins, H. He, G. Williams, R. Baxter, Outlier
     X. Liu, X. Wang, Smart home energy management                 detection using replicator neural networks, in: In-
     systems: Concept, configurations, and scheduling              ternational Conference on Data Warehousing and
     strategies, Renewable and Sustainable Energy Re-              Knowledge Discovery, Springer, 2002, pp. 170–180.
     views 61 (2016) 30–40.                                   [19] P. Malhotra, A. Ramakrishnan, G. Anand, L. Vig,
 [8] M. Castangia, R. Sappa, A. A. Girmay, C. Camarda,             P. Agarwal, G. Shroff, LSTM-based encoder-
     E. Macii, E. Patti, Detection of Anomalies in House-          decoder for multi-sensor anomaly detection, arXiv
     hold Appliances from Disaggregated Load Con-                  preprint arXiv:1607.00148 (2016).
     sumption, in: 2021 International Conference on           [20] M. Thill, W. Konen, T. BΓ€ck, Time series encodings
     Smart Energy Systems and Technologies (SEST),                 with temporal convolutional networks, in: Inter-
     IEEE, 2021, pp. 1–6.                                          national Conference on Bioinspired Methods and
 [9] A. Alsalemi, Y. Himeur, F. Bensaali, A. Amira,                Their Applications, Springer, 2020, pp. 161–173.
     Appliance-level monitoring with micro-moment             [21] Y. Kim, Convolutional neural networks for sen-
     smart plugs, arXiv preprint arXiv:2012.05787 (2020).          tence classification, arXiv preprint arXiv:1408.5882
[10] K. Das, Detecting patterns of anomalies, Carnegie             (2014).
     Mellon University, 2009.                                 [22] S. Bai, J. Z. Kolter, V. Koltun, An empirical evalua-
[11] G. Pang, C. Shen, L. Cao, A. V. D. Hengel, Deep               tion of generic convolutional and recurrent net-
     learning for anomaly detection: A review, ACM                 works for sequence modeling, arXiv preprint
     Computing Surveys (CSUR) 54 (2021) 1–38.                      arXiv:1803.01271 (2018).
[12] I. Ullah, F. Yang, R. Khan, L. Liu, H. Yang, B. Gao,     [23] H. Pan, Z. Yin, X. Jiang, High-Dimensional En-
     K. Sun, Predictive maintenance of power substa-               ergy Consumption Anomaly Detection: A Deep
     tion equipment by infrared thermography using                 Learning-Based Method for Detecting Anomalies,
     a machine-learning approach, Energies 10 (2017)               Energies 15 (2022) 6139.
     1987.
[13] V. Chandola, A. Banerjee, V. Kumar, Anomaly De-
     tection: A Survey. ACM Computing Surveys, vol
     41 (2009) 15.
[14] X. Song, M. Wu, C. Jermaine, S. Ranka, Conditional
     anomaly detection, IEEE Transactions on knowl-
     edge and Data Engineering 19 (2007) 631–645.
[15] Y. Himeur, A. Alsalemi, F. Bensaali, A. Amira, Build-
     ing power consumption datasets: Survey, taxonomy
     and future directions, Energy and Buildings (2020)
     110404.