# Maintenance Prediction through Sensing Using Hidden Markov Models--A Case Study
## 4 Case Study
### HMM--Equipment Diagnostics  
In the HMM model, there are observable states (defined in the previous section) and hidden states (equipment condition). For now, we have chosen three states to characterize the equipment health status: the 1 st representing the good functioning of the equipment, the 2 nd identifying an alert state, and the 3 rd state representing the equipment malfunction. The accuracy of data classification used by the HMM is nothing more than the quantity of correctly validated estimates for all types of events or status classes of a system divided by the total monitoring of the condition of a system, after mounting the model [14]. Thus, through the outputs taken from Clustering, the data were divided into training data and test data to validate the model. Thus, through the outputs taken from Clustering, the data were divided into training data and test data to assess the model. According to the common practice in machine learning, 70% of the data were used to train the HMM model and 30% were used to test the performance of the system in unknown data. Considering that the data are actual time series, the first 70% of the samples were used for training and the latter 30% were used for testing. Then, through the observable training states, based on the Baum-Welch algorithm, we were able to train the HMM to obtain the transition and emission matrices:  
Transition matrix:  
\[\left[ \begin{array}{cccc}Stage&State1&State2&State3\\ state1&0.9113&0.0857&0.0031\\ state2&0.5080&0.4627&0.0294\\ state3&0.0615&0.3291&0.6094\\ \end{array} \right]\]  
Emission Matrix:  
\[\left[ \begin{array}{cccc}Stage&Obs1&Obs2&Obs3\\ state1&0.9892&0.0108&0.0000\\ state2&0.3133&0.6431&0.0436\\ state3&0.0000&0.0000&1.0000\\ \end{array} \right]\]  
Figure 7: Observable states of equipment over time with K-means clustering. Note that the division of data into training data and test data was done in a temporal way, where 70% of training data goes from August 2017 to mid-October 2019, with the remaining months for 30% of test data. In order to find out if this was a good way to divide the data, a comparison was made between the matrices trained by the training data and the matrices trained with the totality of data. Through the Root Mean Square Error metric (Equation (10)), we obtained the following results:  
\[\text{RMSE }=\sqrt{\frac{1}{n}\sum_{ij}^{n}(a_{Data_{Total}}(i,j)-a_{Data_{ Train70}\%}(i,j))^{2}} \tag{10}\]  
\[RMSE_{Transition=0.0709}\]  
\[RMSE_{Emission=0.0289}\]  
Through this metric, we verified that the division performed in a temporal way was a good choice and, from here, we can also take the model to be trained that does not need all the data. Having trained the model, through the obtained matrices, it is now possible to generate observable states and to compare them with 30% of the test data. Then, a comparison is made between the sequence of observable states calculated by the model already trained, and the sequence of observable states that actually exit Clustering (test data). Through the test data, it becomes possible to calculate the probability, \(y\), of such sequences overlapping [58]. In other words, based on the collected data, it is possible to specify the probability of the estimated states corresponding to the real states of the system (Equation (11)). \[y=\left(\sum(HMM_{Observations}=Data_{Test})/n\right)*100 \tag{11}\]  
As the HMM works based on probabilities, 10,000 observation sequences were generated with a number equal to the test data, in order to calculate the respective accuracy and, later, to perform the average, in order to obtain the accuracy of the model in question, which was equal to 78.05%. Having done the training of the model, it is already possible to obtain an HMM scheme for this case study (Figure 8), both with the transition probabilities between hidden states with the probability of emission from hidden states to observable states.