A Prediction Mechanism of Energy Consumption in Residential Buildings Using Hidden Markov Model

: Internet of Things (IoT) is considered as one of the future disruptive technologies, which has the potential to bring positive change in human lifestyle and uplift living standards. Many IoT-based applications have been designed in various ﬁelds, e.g., security, health, education, manufacturing, transportation, etc. IoT has transformed conventional homes into Smart homes. By attaching small IoT devices to various appliances, we cannot only monitor but also control indoor environment as per user demand. Intelligent IoT devices can also be used for optimal energy utilization by operating the associated equipment only when it is needed. In this paper, we have proposed a Hidden Markov Model based algorithm to predict energy consumption in Korean residential buildings using data collected through smart meters. We have used energy consumption data collected from four multi-storied buildings located in Seoul, South Korea for model validation and results analysis. Proposed model prediction results are compared with three well-known prediction algorithms i.e., Support Vector Machine (SVM), Artiﬁcial Neural Network (ANN) and Classiﬁcation and Regression Trees (CART). Comparative analysis shows that our proposed model achieves 2.96% better than ANN results in terms of root mean square error metric, 6.09% better than SVM and 9.03% better than CART results. To further establish and validate prediction results of our proposed model, we have performed temporal granularity analysis. For this purpose, we have evaluated our proposed model for hourly, daily and weekly data aggregation. Prediction accuracy in terms of root mean square error metric for hourly, daily and weekly data is 2.62, 1.54 and 0.46, respectively. This shows that our model prediction accuracy improves for coarse grain data. Higher prediction accuracy gives us conﬁdence to further explore its application in building control systems for achieving better energy efﬁciency.


Introduction
Electrical energy is a very important but scarce resource available to humans. It has become an integral part of our lives and we cannot think of a world without electricity. Many household appliances are running on electricity and its demand is rapidly growing. Industries are also putting more pressure on electricity generating companies to produce more and more energy [1]. According to a report by US-Energy Information Administration (EIA), a 28% increase in global energy demand is expected by 2040 [2]. To meet the rising worldwide demand for energy, efforts are made in two main directions: (a) increase electric power production capacity by exploiting existing and renewable energy sources and solutions (b) effectively utilize existing resources of energy by avoiding energy wastage and unnecessary usage. Both of these approaches are equally important and complement each other. In fact, the effective utilization of existing resources of energy is more desirable because it is economical and easy to adopt. Improper utilization of resources results in energy wastage which can This paper is focused on the development of Hidden Markov Model (HMM) based algorithm to predict energy consumption in residential buildings. We have developed an HMM-based layered architecture for energy prediction in smart homes. The proposed architecture has four layers (a) Data acquisition layer is used to collect data including indoor environmental parameters, actuators status, and users occupancy information; (b) Pre-processing layer prepares the context data for upper layers; (c) Afterwards, hidden Markov models are generated and stored; (d) Finally, computed models are used at the application layer for energy prediction. For experimental analysis, we have used the data collected from four multi-storied buildings located in Seoul, South Korea. Comparative analysis shows that proposed model has achieved better results than Support Vector Machine (SVM), Artificial Neural Network (ANN) and Classification and Regression Trees (CART).
The rest of the paper is structured as follows. Section 2 present a brief overview on related work. A detailed discussion of hidden Markov modeling for proposed system is given Section 3 along with its pseudo code and flow diagram for HMM generation and training. The architecture of proposed HMM-based model for prediction of energy consumption is discussed in Section 4 along with its design. A brief discussion of collected data and its transformation is presented in Section 5. Section 6 presents model validation, comparative and temporal analysis along with a detailed discussion on results. Finally, the paper is concluded in Section 7 along with future work directions.

Related Work
Energy is considered as one of the most important and scarce resources due to the constant increase in its demand. Energy saving is not only desired for promoting a green environment for future sustainability but also important for the home users and energy production companies. Consumers want to reduce their monthly expenses in which electricity cost is a major contributor. Power generating companies are under pressure for producing more energy to fulfill commercial and domestic energy requirements. Thus, solutions for efficient energy utilization is desirable by all stock holders.
In the recent past, tremendous efforts have been invested in building smart homes solutions by researchers and manufacturing industry. In smart homes application domain, diverse nature of research directions can be found ranging from monitoring, prediction, optimization, security, privacy, and control. Energy optimization is also a profound area of research in building smart grids and smart homes. The objective is to provide maximum user comfort at the cost of minimum energy consumption [7][8][9].
Development of building energy management systems have been investigated based on various control systems [10][11][12]. Among the major reasons for energy inefficiencies and overutilization is that trivial systems often do not consider environmental factors and user occupancy. For instance, typical heating, ventilation, and air conditioning (HVAC) systems will assume that space is fully occupied and it will try to maintain the desired atmosphere without caring if a hall is fully occupied or only a few persons inside. Various algorithms are applied to predict user occupancy and corresponding energy requirement in order to improve system efficiency. Support vector machine and artificial neural networks-based algorithms are the two most widely used algorithms for energy prediction [13]. For instance, to improve the efficiency of a steam boiler in buildings, a data-driven scheme is proposed in [14] using artificial neural networks to achieve optimal cooling/heating. Their model can be used for estimation of steam consumption in future using forecasted weather data. Similarly, a model predictive control (MPC) based system is developed in [15] for saving of energy consumed by heating systems in buildings. Using forecasted weather data together with users occupancy information, the behavior of the building is modeled in terms of selected operational strategies. Their goal is to develop a control system that can achieve user desired parameters settings with minimum energy consumption. For indoor comfort and energy management, an intelligent multi-agent optimization based control system is presented in [16]. They try to achieve maximum user comfort with reduced energy consumption by fusing information using weighted aggregation.
Building energy management systems can be classified broadly into two categories based on adapted modeling strategies i.e., inverse and forward modeling [17]. A system based on an inverse modeling scheme tries to capture the dependencies among various inputs (e.g., users occupancy data, weather information, building structural parameters) and output data (i.e., required energy) in the form of a mathematical equation. However, this kind of system requires strong background knowledge to derive such a mathematical expression. In contrast, a system based on forward modeling schemes tries to generate an optimal schedule for operation along with estimated required energy by using input data such as building structural design parameters (e.g., size, material) along with weather and environmental information. Many software frameworks based on forward modeling schemes can be found in the literature. A comparative study of two of the most popular forward modeling-based software packages i.e., EnergyPlus and DOE-2 can be found in [18]. DOE-2 is famous simulation tool for energy usage estimation in residential and commercial buildings. Recent development in information and communication technologies (ICT) has given birth to new modeling schemes i.e., data-driven. Data-driven models are based on input data regarding outdoor and indoor environment collected through various sensors. In fact, this new sensor technologies-based data-driven approach is a hybrid model of both forward and inverse model for energy management. Forward models are based on input data which is supplied by various sensors readings. Inverse models are based on some mathematical relationship between inputs and outputs which can be derived by using various statistical or machine learning algorithms. A comprehensive review of data-driven approaches for prediction of energy consumption in buildings can be found in [19]. Since inception, sensing technologies-based models for energy management have attracted significant research attention. Several energy management systems are proposed in the literature for estimation and prediction of energy consumption by using hybrid models i.e., a combination of sensing technology with artificial intelligence algorithms. For instance, a study presented in [20] illustrate the application of several statistical methods in order to improve neural networks prediction for efficient energy consumption in buildings. Similarly, a hybrid model of adaptive-neuro-fuzzy system with genetic algorithm (GA-ANFIS) is presented in [21] for further improvement of conventional neural networks. Significant improvement in prediction results is reported by using the proposed hybrid model. Ali et al. proposed a hybrid energy prediction model to improve power consumption optimization based on pre and post processing in [22].
For required heating load prediction, Kalogirou et al. used back propagation neural networks for given parameters of building space such as windows area and type, walls size, ceiling design, etc. [23]. Olofsson and Andersson [24] developed a model for making long-term predictions of energy demand based on short-term recorded data using neural networks. The model parameters include temperature difference between indoor and outdoor environment and energy required for heating and other utilities. A study presented in [25] shows that accuracy of prediction algorithms deteriorates as they try to predict further ahead in future. They also observed that algorithms can normally predict the peak energy consumption up to one week ahead of time with 80% accuracy. A comprehensive survey of neural networks based energy applications in buildings is presented in [26].
User occupancy-based system for efficient utilization of HVAC energy is proposed in [27] based on Markov model. They have used real-time occupancy data collected from various sensors to evaluate their system. Results of simulation in EnergyPlus simulator shows that 42% annual savings can be achieved by using context-aware system. In [28], a context-aware model for user occupancy prediction in the building is proposed using Semi Markov Models. Using historical occupancy data along with current contextual information, occupancy models are created for different zones of building with varying time intervals for short and mid-term prediction. Hidden Markov Models (HMM) are useful in time series data analysis, however, its application in building energy sector is not so much investigated. Tehseen et al. has developed an HMM-based procedure in [29] for identification of individual household appliances from collective energy consumption data. However, this requires HMM models to be trained for individual appliance energy consumption profile. An HMM-based modeling scheme is presented in [30] for energy level prediction in wireless sensor networks nodes. They consider node energy level as a stochastic variable having values within certain fixed range forming hidden state for their HMM model whereas nodes energy consumption is treated as observed state. HMM model is trained during operation of WSN and used to predict energy levels for the sensing nodes in order to maximize network overall lifetime. HMM models are also used to predict description of device behavior based on training through previously collected energy consumption data for an individual devices [31]. This model requires a system with known composition and cannot be applied to residential buildings where system load is constantly changing. Besides energy prediction, HMM-based models are used for other purposes, e.g., an input/output hidden Markov model is developed by Gonzalez et al. for electricity prices modeling and prediction in [32].
In this paper, we have proposed a Hidden Markov Model based algorithm to predict energy consumption in smart buildings. We have used energy consumption data collected from four multi-storied buildings located in Seoul, South Korea for model validation and results analysis.

Hidden Markov Modeling for Proposed System
Markov chain/models are named after its inventor Andry Markov who is known for his studies on stochastic processes. Basic Markov models are useful for finding long-term steady-state probabilities of the system having a finite number of possible states, using inter-state transition probabilities. Many variations of basic Markov model are used in diverse applications. Hidden Markov Model (HMM) is an advanced form of basic Markov model that is specifically formulated for the phenomenon where system state is not directly visible i.e., hidden, but output, depending upon the internal states, is visible. In HMM, we have hidden and observed states, state probability vector v i , inter-state transition probability matrix A i and emission probability matrix B i as shown in Figure 2. Hidden states represent the system internal states which is normally not directly visible to the user. Observed states are directly visible to the user and can be used to make an intelligent guess about system's corresponding hidden state. State probability vector v i gives information about the probability of the system being in any state at a given instant of time. Inter-state transition probability matrix A i express the probability of going from one hidden state to another. Emission probability matrix B i is used express the relationship between hidden and observed states, governing the distribution of the observed state at a particular time given the information about system hidden state at that time.   For HHM models generation and training, we have used hourly energy consumption data collected from smart meters installed in the selected residential building of Seoul, South Korea for period of one (01) year. Through data transformation process, we convert the hourly energy consumption data to get floor-wise occupancy sequence. Details about data transformation process is provided in Section 5. Through this transformation, we get numerous different combinations for occupancy sequence. With every occupancy sequence, we have associated a class label based on total energy consumption. It is quite understandable that same occupancy sequence may result in different total energy consumption on different floors, on different days, on different timings. Let S be our set of all occupancy sequences. For every s ∈ S, we have corresponding class label for energy consumption i.e., E s . Depending upon the unique values in the input sequence, we also assign a state label to each sequence L s . Let, T be the total number of classes in our data where each class corresponds to a unique combination of E s and L s . Similarly, we can express a total number of unique labels for energy consumption as Y (irrespective of occupancy sequence). A brief description of the terms used in our HMM is given in Table 1. There are three main phases:

HMM Models Creation and Initialization
First, we create desired number of HMMs for the available dataset. Total 108 different models are created as we have 108 unique combinations of class and state labels in our dataset. All these models are initialized with starting transition and emission probabilities and finally stored in hmmc structure. Let M i be the ith HMM model which is expressed as below: where v i is the state probabilities vector, A i is the inter-state transition probabilities and B i is the emission probabilities. These probabilities vectors/matrices are initialized as below: where L i is number of unique values in corresponding input sequence s.
Above scheme ensure summation of all row vectors to be 1 to satisfy Markov condition. Figure 2 shows the typical structure of ith HMM model after initialization.

HMM Models Training
In the second phase, we train the models with the available dataset. For every unique combination of energy label E s and state label L s , we have created a hidden Markov model with initial probabilities as shown in Figure 2. For training of each specific model, first, we extract set of corresponding input sequences that have same energy label E s and state label L s . Baum-Welch algorithm is used for training of HMMs [34]. For given set of training observation sequences and initial structure of HMM (numbers of hidden and visible states), Baum-Welch algorithm determines HMM parameters (state transition and emission probabilities) that best fit to the training data. After, model training, these probabilities are replaced with system steady-state probabilities for each model. Flowchart given in Figure 3 explains the initialization and training process of our HMMs.

Floor wise Hourly Energy
Consumption Data

HMMs Construction and Initialization
Observed State  Figure 3. Flowchart of HMMs construction, initialization and training.

Prediction using HMM Models
Finally, we perform prediction for every input sequence to compute predicted energy consumption. Here, we compute the likelihood (probability) of every trained HMM model for generating the given input sequence using Baum-Welch's forward algorithm. As we have created T HMMs and each model is trained for a particular energy consumption (energy label) using corresponding estimated occupancy sequence. Thus, for any given occupancy sequence s, we will compute the likelihood for every ith model to generate given input observation sequence i.e., P i = M i (s). The model with maximum likelihood will be selected and its corresponding energy label will be considered as predicted energy consumption as shown in Figure 4.  Figure 4. Energy prediction from observed occupancy data using Hidden Markov Model. Figure 5 presents pseudo-code for HMM creation, training and testing based on Accord.NET framework [33].   Figure 6 presents the architecture of our proposed system for prediction of energy consumption in smart buildings based on Hidden Markov Model. System functionality is covered in four layers, each having designated components for a specific task. Brief description of each layer is given below.  Figure 6. Proposed energy prediction model using HMM.

Data Acquisition Layer
This layer composed of physical IoT devices including various sensors and actuators. Sensors are used to collect contextual information e.g., environmental conditions, temperature, humidity, user occupancy, etc. To detect user occupancy, various Passive Infra-Red (PIR) sensors can be used to get binary information about occupancy i.e., occupied or not occupied. To get actual user count, cameras will be required to install on transition point between various zones of the building. After processing of the collected data, home appliances can be controlled accordingly by sending control commands to the actuators. For theses experiments, we have only used the energy consumption data collected via smart meters installed on each floor of selected four buildings. Energy consumption data is recorded on hourly interval basis for a period of one year i.e., from 1 January 2010 to 31 December 2010. Figure 7 provides 2 days sample view of collected data for a single building having 33 floors.

Pre-processing Layer
In this layer, we perform some data transformation operation in order to get the data in the format required by the upper layer. This also includes data smoothing filters in order to reduce the number of states in our Markov model. Furthermore, smoothing helps in removing the outliers and anomalies from the data. Various smoothing filters can be used for this purpose e.g., moving average, loess, lowess robust loess/lowess etc. Detailed discussion on data transformation is given in next Section 5.

Markov Model Construction Layer
This is the most important layer where we construct hidden Markov models in order to perform energy prediction. First, we obtained the observed state's information from given data and then interstate transition probabilities are calculated using hourly data. Detailed discussion on model creation, state transition and emission probabilities calculations along with model training is covered in Section 3. Once, Hidden Markov Models (HMM) are trained then they are stored in memory for onward usage by the upper application layer.

Application Layer
In this layer, we use the trained HMM for given sequence of observed data to get the best matching HMM. Depending upon the dataset, we obtain T different Markov models; each model is trained rigorously for a particular type of input sequence. For a given input sequence of occupancy information, each individual model matching is calculated. Finally, the best matching model is selected and its output is considered as predicted energy consumption as shown in Figure 4. We also compare our predicted energy consumption result with actual data to compute mean squared error.

Data Collection and Transformation
Given the occupancy pattern information, we can predict energy consumption. In the available data, we have floor-wise hourly energy consumption information collected from smart meters installed in the selected residential building of Seoul, South Korea for period of one (01) year i.e., January 2010 to December 2010. To have an idea about dataset, hourly energy consumption distribution for complete data-set is provided in Figure 8 in the form of box plot. We can easily figure out from the box plot that energy consumption is low in early morning and afternoon where peak energy consumption is observed during noon and night timings. This is due to the fact that residential buildings have maximum occupancy during noon and night times which results in higher energy consumption. This also indicates that there is a strong positive correlation between energy consumption and occupancy in the collected dataset. We can relate user occupancy data with hourly energy consumption by using simple linear transformation but we cannot directly conclude total energy consumption from given occupancy information. For example, two rooms having same user occupancy but different electrical equipment will have different energy consumption ratio. However, if we can have user occupancy pattern then we can predict total energy consumption. Therefore, we need to transform the existing data into a sequence in order to get observation sequence for our Hidden Markov Model. As we observed from data that there is a strong positive correlation between energy consumption and occupancy, so mathematically we can express it as below.
where Energy F i is energy consumption at ith floor, Occup F i is estimated occupancy of the ith floor and C is proportionality constant i.e., per occupant per hour energy consumption. Assuming per person per hour power consumption to be about 10 kWh (approximately), we consider C = 10 in these experiments. Using a different value of C will results in a different observation sequence for HMM but it will rarely affect the model results as the output (i.e., total energy consumption) remains the same for which model is trained. To get estimated occupancy information from consumed energy, we can re-write Equation (6) as below.
Afterwards, we apply data smoothing filter in order to reduce the number of state transitions using moving average filter with a span of 3 using Equation (7).
After smoothing filter operation, the resultant data has a fractional part which is simply removed by rounding the data to the nearest integer value as each value form a state in Markov model. Table 2 illustrate these operations on sample data. Number of states are calculated by computing the unique values in input data sequence and state transitions are calculated by counting the number of state changes while moving from left to right of input data sequence. We can see that after smoothing, the number of states reduced from 5 to 4 and inter-state transitions from 7 to 5 for this sample data. Finally, we get user occupancy data as an observation sequence and for which we use Hidden Markov Model to predict energy consumption as shown in Figure 9. Floor-wise per hour energy consumption data gives us user occupancy pattern in the building which serves as input (observation sequence) to our Markov model whereas total energy consumption for a particular input pattern is associated with the model as a tag which is also referred as a predicted class label. For each input sequence, we have defined a class label, depending upon the total energy consumption for corresponding input sequence e.g., if total energy consumption for a particular input sequence is N (say N=36) then we assign that sequence with a class label as EN i.e., E36. Furthermore, for every input sequence, we also record a state count i.e., the number of unique values in corresponding input sequence as shown in the third column in Figure 9.

Model Validation
For model validation and experimental analysis, we have used real data collected from smart meters installed in the four selected multi-storied residential buildings of Seoul, South Korea for period of one (01) year i.e., 1 January 2010 to 31 December 2010. The number of floors in each building are 33, 15, 36 and 33, respectively. Smart meters are installed at each floor sub-distribution switchboard and are connected to the main Server. Energy consumption data is recorded on hourly interval basis for the stated period of one year and the unit of measurement used for energy consumption is kilowatt-hour (kWh). The dataset has floor-wise hourly energy consumption information for selected four residential buildings. Sample view of collected data for two days is provided in Figure 7 for an anonymous building-IV having 33 floors. This is just to give an idea about data distribution. Furthermore, hourly energy consumption distribution for complete data-set is shown in Figure 8 in the form of box plot.
For these experiments, we have used 70% of available data for training and rest of the 30% is used for testing. Figure 10 shows comparison results of predicted energy consumption with original data values for the testing dataset. The results show that both lines are almost going side by side which indicates that our prediction algorithm is working nicely. To get better insight, we present absolute error difference results in Figure 11. Absolute error in prediction graph reveals that most of the values lie within [−4, +4]. Root mean squared error (RMSE) for the given result is 2.62 which is quite reasonable. These results not only validate the model but also gives us the confidence to perform a comparative analysis with other prediction algorithms.

Comparative Analysis
For purpose of comparative analysis, we choose three algorithms i.e., Artificial Neural Network (ANN) [35], Support Vector Machine (SVM) [36], and Classification and Regression Trees (CART) [37]. These three algorithms were applied on the same datasets to compute predicted energy consumption. Configuration settings used for ANN, SVM and CART algorithm are given below.

Artificial Neural Network (ANN)
We have used default Feed Forward Neural Network available in MATLAB 2013a [38] with Levenberg-Marquardt training method having 4 input features i.e., hourly data along with weekly, weekday and monthly information. ANN implementations available in Matlab provide automatic scaling of input data into [−1, +1]. As we have used the default implementation of ANN available in Matlab, therefore we need not pre-process the input data. Levenberg-Marquardt training algorithm is selected because it is considered to be the best and fastest method for moderate size neural networks. The output of the neural network is predicted consumed energy. We have used tan-sigmoid(x) as our activation function at the hidden layer and linear function at the output layer. Different models of ANN are tested with varying number of neurons in the hidden layer from 4 to 30. Parameters of ANN algorithm are fine-tuned and the reported results are the best that we obtained after a number of repeated experiments. Screenshot of AAN configuration given in Figure 12 taken when training process was completed. Maximum number of epochs used to train the network is 100.

Support Vector Machine (SVM)
SVM is another very popular algorithm that was initially developed for binary classification problems [39]. Currently, its many variations are available to solve complex classification and regression problems [36,40] using kernel tricks. Depending upon problem input size and nature, appropriate kernel function can be selected among linear, polynomial, radial, etc. For kernel selection, we performed experiments with three different kernels i.e., linear, polynomial and radial basis function (RBF). Results with linear kernel were the best and are reported in this paper. In these experiments, we have used default model of SVM in MATLAB 2017b [41] with sequential minimal optimization (SMO) optimizer and box constraint C = 1, The model converged after 25,000 iterations with = 1.49. Parameters of SVM algorithm are fine-tuned and the reported results are the best that we obtained after a number of repeated experiments. SVM implementations available in Matlab provide automatic scaling of input data into [−1, +1], therefore we need not pre-process the input data for SVM algorithm.

Classification and Regression Trees (CART)
For CART, we also use default CART implementation available in MATLAB 2013a [38]. CART decision is created using regression method. Default regression tree has 120 levels and best prediction results were obtained with pruning last 5 levels. Like ANN and SVM, parameters for CART algorithm are fine-tuned and the reported results are the best that we obtained after a number of repeated experiments. Screenshot of pruned CART tree obtained for prediction of energy consumption is given in Figure 13. Absolute error in prediction results of our proposed model together with ANN, SVM and CART results is shown in Figure 14. It can be seen that results of all the four algorithms look quite similar. Significant difference is not visible from this figure. Just like results of the proposed model, absolute error in prediction for SVM, ANN and CART also remain within [−4, +4] for most of the values and there seems no significant difference. In such cases, when the difference is not obvious from graphs/plots then statistical measures are very useful. These measures not only summarize the data but also help in analyzing the data by quantifying the accuracy of results. Thus, it can reveal the relative difference which may not be visible, otherwise.

Statistical Measures used for Comparison
Brief description and formula of four statistical measures used for comparative analysis are given below.

•
Mean Absolute Deviation (MAD): This is the sum of absolute differences between the actual and predicted value, divided by the number of data items.
• Mean Squared Error (MSE): This is the most widely used error metric. It penalizes more when error gets increased as squaring a number grows exponentially from small to big numbers. The MSE is calculated by adding the squared errors and dividing it by the number of data items.
• Root Mean Square Error (RMSE): This is obtained by taking the square root of MSE.
• Mean Absolute Percentage Error (MAPE): This is the average of absolute errors divided by the original values, multiplied by 100 to get result in percentage.
where n is the total number of entries in the testing dataset, D i is the actual energy consumption (kWh) for ith instance in the dataset andD i is the corresponding predicted energy consumption (kWh). These statistical measures give us a single number to quantify prediction accuracy. If prediction results are more closed to actual energy consumption then corresponding values for these statistical measures will also be small. An algorithm having smallest values for these statistical measures will be the best. Table 3 presents the statistical summary of the results for comparison among the four algorithms. Proposed model results outperform the other three algorithms on all statistical measures. Artificial neural networks results are second best and it has a very low difference when compared to our hidden Markov model results. Relative accuracy of proposed model results is 2.96% when compared to ANN results in terms of RMSE metric. However, it is 6.09% better than SVM and 9.03% better than CART results. Higher prediction accuracy gives us confidence to further explore application of the proposed model in building control applications for achieving better energy efficiency.

Temporal Granularity Analysis
To further establish and validate prediction results of our proposed model, we have performed temporal granularity analysis. Figure 10 shows energy prediction results based on hourly data. Here, we analyze the impact of temporal granularity on the prediction accuracy of our proposed HMM model. For this purpose, we have performed daily and weekly data aggregation. Figures 15  and 16 show the prediction results for daily and weekly aggregated data. Prediction accuracy in terms of root mean square error metric for hourly, daily and weekly data is 2.62, 1.54 and 0.46 respectively. This shows that our model prediction accuracy improves for coarse grain data. We have also evaluated the performance of other algorithms (ANN, SVM, and CART) for daily and weekly predictions and their results were lower than proposed HMM scheme, therefore not reported in the paper.

Discussion on Results
Overall, our results indicate that our proposed HMM model performs well as compared to ANN, SVM and CART algorithm. For given application scenario, its quite understandable that same observation sequence can result in different energy consumption in different buildings. This is due to the fact that total energy consumption depends not only upon the observation but also the nature of equipment and appliances installed in respective buildings. Like for instance, per hour energy consumption for room A and room B will be different even though both having same number of occupants if different types of appliances are installed in each room. In given application scenario, we can only have information about users occupancy sequence but no information about the details of appliance installed on each floor. Furthermore, HMM works well to discover the underlying structure and information and thus results in better prediction accuracy as compared to ANN, SVM and CART because HMM model uses the extra state information along with observation sequence and total energy consumption. A separate HMM model is trained for every unique combination of total energy consumption and states information which helps HMM model to accurately predict energy consumption for a given observation sequence.
Furthermore, we observe that our model prediction results for coarse grain data i.e., weekly is much better than the results for fine grain data i.e., hourly. In other words, it is inherently harder to predict at smaller time intervals due to the stochastic nature of energy consumption as for fine grain data, the variation in observation sequence is minor which is difficult to capture. Analyzing the results of HMM model over the larger time interval (daily and weekly) reveals improvement in prediction accuracy in terms of root mean square error metric. This is due to the fact that, for larger time intervals, the variation among individual observation sequences becomes distinct and more visible which is easily captured by HMM. Another reason for the improvement in prediction accuracy for coarse grain data is that the number of observation sample gets reduced. Thus for a relatively smaller number of distinct observation sequences, HMM model is able to produce better results. However, there are some mis-predictions for weekly aggregated data as shown in Figure 16. For sake of illustration, we consider three sample cases for investigation i.e., week-1, week-5, and week-9. These three cases are carefully selected to better analyze the model prediction accuracy. The week-1 case is an example case for mis-prediction. Week-5 and week-9 are example cases for accurate prediction of energy consumption i.e., 6500 kWh and 6400 kWh respectively. Predictions results for week-5 and week-9 are accurate, however, there is some error in prediction for week-1, where predicted energy consumption is 6400 kWh, while actual energy consumption is 6500 kWh as shown in Table 4. Table 4. Details of three sample cases in weekly data.
Week No.

States Actual Consumption (kWh) HMM Prediction (kWh)
Week-1 20- It is evident from Table 4 that all three weeks' data is different. Here, the week-1 case is unique due to a different number of states as compared to week-5 and week-9. Our proposed algorithm has predicted total energy consumption of 6400 kWh for week-1 which means that week-1's observation sequence is more like week-9's observation sequence. To further validate this assertion, we have cross-checked similarity indexes of the three cases and its results are shown in Table 5. Table 5. Pairwise cosine-similarity among selected three weeks observation sequence.
Week-1 Week-5 Week-9 Overall, similarity index values in Table 5 indicate that all three cases are highly similar and there is a minor difference between them. However, contrasting cosine-similarity between wee-1↔week-5 and week-1↔week-9, we can see that the week-1 case has relatively more resemblance to week-9 as compared to week-5, therefore total energy prediction results for week-1 case are same as week-9. This also signifies that our proposed model is able to capture the minute difference of 0.0004 and accurately relate week-1 to week-9 which results in mis-prediction, unfortunately.

Conclusions and Future Work
In this paper, we have presented a hidden Markov model-based algorithm for prediction of energy consumption in smart buildings. We have used real data collected through smart meters in selected buildings at Seoul, South Korea for model validation and results analysis. Proposed model prediction results are compared with three well-known prediction algorithms i.e., ANN, SVM, and CART. Statistical analysis shows that our proposed model results are 2.96% better than ANN results in terms of RMSE metric, 6.09% better than SVM and 9.03% better than CART results. To further establish and validate prediction results of our proposed model, we have performed temporal granularity analysis. For this purpose, we have evaluated its results for hourly, daily and weekly data aggregation.
Prediction accuracy in terms of root mean square error metric for hourly, daily and weekly data is 2.62, 1.54 and 0.46 respectively. This shows that our model prediction accuracy improves for coarse grain data. Higher prediction accuracy gives us the confidence to explore proposed model application in building control systems for achieving better energy efficiency. We have selected HMM for prediction due to its inherent benefits over other AI-based algorithms. HMM-based trained models can be used to identify underlying appliances used from cumulative energy consumed. Furthermore, HMM models can perform automated fault monitoring and appliances health assessment by performing analysis of individual device energy consumption pattern. At the first step, we tried to establish that HMM models can accurately predict energy consumption which was the subject matter of this paper. These initial results give us confidence and we are currently exploring various alternatives and collecting data to extend this work in aforementioned directions.