## 6 Materials and Methods
### Data Preparation and Preprocessing  
The raw data are represented by the matrix \(\textbf{X}=[\textbf{x}_{1},\textbf{x}_{2}\ldots\textbf{x}_{N_{T}}]\), where \(N_{T}\) is the number of time steps during which each \(\textbf{x}_{t}\in\mathbb{R}^{N_{x}}\), where \(N_{x}\) is the number of input features. The raw data come directly from the field, and in order to use them as an input for the model, it is important to prepare the data in a correct way. In fact, even though there are many available techniques for data scaling, choosing the best scaling method continues to be one of the most challenging problems because the performance of ML algorithms and the selection of standardization methods are interconnected [68; 69; 70]. For the proposed approach, based on the reduced computational resources available, six different types of data preparation are used:  
* Data rectification: Generally, when the machine is not running, it is not turned off, and therefore, the data, such as voltage, frequency, etc., continue to have a non-zero value. Analyzing the data when the machine is not working, when the phase current is equal to zero, is useless for our purposes, so, in order to reduce the size of the time series, the data during the off period have been removed.
* Data cleaning: The whole dataset not only contains information about electrical parameters but also generic information such as serial numbers, IDs, and time information is not useful. This type of information does not support analysis of the anomaly estimation.  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Variables** & **Variables** \\ \hline Line voltage V1, V2, and V3 & Phase THDV12, THDV13 and THDV23 1 \\ Phase voltage V12, V13, and V23 & THDA1, THDA2, THDA3 and THDAN 2 \\ Phase current A1, A2, A3, and An & Frequency \\ Phase active power P1, P2, and P3 & HaA1 from 0 th to 15 th 3 \\ Phase apparent power S1, S2, and S3 & HaA2 from 0 th to 15 th 3 \\ Phase reactive power Q1, Q2, and Q3 & HaA3 from 0 th to 15 th 3 \\ Phase power factor P1, PFE2, and PF3 & Phase DPFI, DPF2 and DPF3 4 \\ Line THDV1, THDV2, and THDV3 1 \\ \hline \hline \end{tabular}  
* Total harmonic distortion of the voltage waveform. 2 Total harmonic distortion of the current waveform. 3 Harmonic components of phase current. 4 Displacement power factor.  
\end{table}
Table 1: List of acquired variables.  
Figure 10: Example of acquired data.  
* Data operation: A type of data operation has been performed in order to adjust the values of the numerical columns of the dataset to a standard scale. Specifically, the data has been standardized to a probability distribution in which the mean is zero and the standard deviation is 1 according to Equation (17): \[\mathbf{X}_{std}=\frac{\mathbf{X}-\boldsymbol{\mu}_{\mathbf{X}}}{\boldsymbol{ \sigma}_{\mathbf{X}}}\] (17) where \(\boldsymbol{\mu}_{\mathbf{X}}\in\mathbb{R}^{N_{x}}\) is the mean, and \(\boldsymbol{\sigma}_{\mathbf{X}}\in\mathbb{R}^{N_{x}}\) is the standard deviation of the time series.
* Dataset splitting: The dataset consisted of 269 time series (\(N_{n}\)) with 300 time steps (\(N_{t}\)) and 88 features (\(N_{x}\)). The training set is about 60%, and the validation and test sets are about 20% and 20%, respectively.
* Data labeling: The validation and test sets present faults from halfway through the time series to the end. These anomalies are emulated by summing the noise with the original time series. The noise is generated from a normal distribution and is multiplied by 20% of the standard deviation of the dataset. Class 0 is used for no faults and Class 1 for the added faults.