# An EWS-LSTM-Based Deep Learning Early Warning System for Industrial Machine Fault Prediction
## 4 The Case Study Phases and Results
### The Dataset Elaboration  
Data are collected on the machine's edge devices and sent to the gateway according to Algorithm 1, which can be summarised as follows: ship the data every time a value among those monitored changes or every 360 s (6 min), no matter if values are changed or not. This approach creates a dataset in the form \(<\mathit{Timestamp}>,<\mathit{feature}\ name>,<\mathit{Value}>\). The total number of sensors on the embosser provides a total number of 34 numerical characteristics, representing each monitored part, and a class that defines the type of operation for a given \(\mathit{Timestamp}\).  
This is essentially of two types:  
* Error, along with a \"type\", represents the different nature of the error;
* Normal functioning defines that the machine is operating correctly.  
The initial analysis of the dataset is based on the conversion and processing of the cloud-stored data into a set of rows corresponding to _time-feature_ pairs. To ensure better data handling procedures, features and classes have been processed around a single _Timestamp_ with a pivoting procedure. There are some caveats when using this approach: as rows are grouped and rotated into a matrix, certain features may become \(null\) due to incomplete data for the specific \(\mathit{Timestamp}\).  
```
1:\(F_{1}(t)\dots F_{N}(t)\) set of features values acquired over time
2:procedure Send data
3:\(t\gets 0\)
4:while True do
5:if\(t=360\)then\(\triangleright\) Every 6 min
6: bulk send \(F_{1}(t)\dots F_{N}(t)\)
7:\(t\gets 0\)
8:else
9:for\(i=1\dots N\)do
10:if\(F_{i}(t)\
eq F_{i}(t-1)\)then
11: send \(F_{i}(t)\)
12:endif
13:endfor
14:\(t\gets t+1\)
15:endif
16:endwhile
17:endprocedure
```  
**Algorithm 1** Data collection.  
To address this situation, Algorithm 1 is used, where it is noticed that the \(null\) values can be handled through forward and backward filling. This process involves the replication of the closest non-null value for each feature, both forward and backward, until it changes. By doing so, the original structure of the dataset is maintained, and if \"not updated\", the value of a feature remains constant over time.  
Table 2 presents an example of how \(null\) values have been handled through the pivot procedure. For simplicity, only a general approach is presented, considering timestamps \(t\pm 2\), where \(\{x,y,z,t,v\}\in\mathbb{R}\). The forward-fill procedure replicates, for each feature, its value from the most remote non-null timestamp until it changes (refer to Feature 1 and Feature 2 in Table 3). Similarly, backward fill is used to fill values from the most recent non-null timestamp part of the dataset towards the beginning (see \"Feature n\" in Table 4). Particular attention was paid to the class variable in the dataset, as it required a different treatment compared to the other features. The forward-fill procedure does not change from what has just been described; however, the backward fill does not guarantee that the missing value is replicated until the beginning of the dataset, when it encounters an errorcode. For this reason, the backward-\(null\) values were filled with the corresponding class of \"normal behaviour\".