# A Real-Time Novelty Recognition Framework Based on Machine Learning for Fault Detection
## 3 Proposed Predictive Maintenance Architecture
### AI Unit
The operator can choose one of the three models depending on the application in which the framework operates: for example, if there are no \"computational effort thresholds\", such as a workstation or a computer, a Random Forest Regressor can be used to obtain an accurate prediction, while if the aim is to deploy the framework in a stand-alone embedded device, a Linear Regressor or a Decision Tree Regressor can be used in order to reduce the overall computational effort. The paper's framework is uploaded in a workstation to compute the predictions and results; hence, a Random Forest Regressor is chosen as the reference model. Furthermore, different errors were also evaluated during the study: Squared Error (SE), Mean Squared Error (MSE), Root Mean Squared Error (RMSE), and Mean Absolute Error (MAE), with the shape reported below:  
\[SE(y,\hat{y}) =\sum_{i=0}^{n-1}(y_{i}-\hat{y_{i}})^{2}\] \[MSE(y,\hat{y}) =\tfrac{1}{n}\sum_{i=0}^{n-1}(y_{i}-\hat{y_{i}})^{2}\] \[RMSE(y,\hat{y}) =\sqrt{\tfrac{1}{n}\sum_{i=0}^{n-1}(y_{i}-\hat{y_{i}})^{2}}\] \[MAE(y,\hat{y}) =\tfrac{1}{n}\sum_{i=0}^{n-1}|y_{i}-\hat{y_{i}}|\]  
where \(y_{i}\) is the real value while \(\hat{y_{i}}\) is the predicted one. Figure 7 shows different error pictures computed on the same predictor using a Random Forest Regressor (RFR). As shown in Figure 7 there is a substantial difference between the obtained results; the last two graphs are more disrupted than the first two because they follow the prediction's behavior faster. As in the AI model selection case, there is no particular rule for the error  
Figure 7: Errors evaluation. model selection. A possible solution could be to configure all four error models to monitor the deviation by creating dedicated predictor agents to perform the computation, but this creates waste from a computational energy point of view. The latter two error models show very similar behavior because of the huge likeness in the formula behind them; with the same number of samples, the MAE has \(1/n\) while RMSE has \(\sqrt{1/n}\), multiply the square root member. The similarity in the graphs above is due to the number of data used for the computation: when the number is low, the \(1/n\) and \(\sqrt{1/n}\) are very comparable, also bringing a similarity in the results obtained. In this case, the operator can again choose which error model or which error models the framework has to use to monitor the behavior of the machine. In this paper and the following case studies, the error chosen for the evaluation is the MAE. Figure 8a,b show two examples in which the error is computed with two sample ranges \(n\); Figure 8a shows the last two records while Figure 8b shows the last five records:  
A two-sample error is chosen for the following experimental executions because of its ability to predict quickly. Another ability of the main framework concerns the possibility of updating or retraining the already trained models: as explained above, Novelty Detection can understand when something new happens in the system; this change can be related to an issue or a change does not create any problem. For this reason, when a novelty appears, the maintainer has to examine if the problem truly exists in order to choose one of the following procedures:  
* Models Update: in the case in which the data collected are different from the trained ones, but this change is not related to an issue in the machine, the maintainer can update the framework with the last parametrized \(n\) data, considering the incoming data as good ones. Thanks to the models' update, a substantial reduction of the error value is performed;
* Models Retrain: when a problem or a component substitution is performed in the machine, the retraining process is necessary due to the inevitable data change in the prediction (a common change could be a shift error in the data collected). The maintainer can decide to retrain the models by neglecting all previous ones and returning to the beginning phase.