## 3 Methodology
#### Fault Detection Algorithm
In the proposed algorithm, the kNN model is best fitted for fault diagnosis based on a predefined fault and confusion array because the dataset is small to moderately sized, the feature space is low-dimensional, and the fault classes are well separated. In this case study, the simplicity, ease of implementation and effectiveness of the proposed method in scenarios with distinct clusters of faults make it a viable choice for real-time and straightforward fault diagnosis applications. However, careful consideration of the dataset's size and dimensionality is critical to ensure kNN's efficiency and accuracy in fault diagnosis. Therefore, a confusion array/chart and the derived metrics are crucial for assessing performance and guiding the selection of the best model for fault diagnosis, providing a summary of prediction results by showing the counts of true positives, false positives, true negatives and false negatives. The confusion chart (cm) visually represents the performance of the kNN classifier by displaying the actual versus predicted class labels, which helps assess the model's accuracy and identify any misclassifications (8). The confusion chart's rows correspond to the true class, the columns correspond to the predicted class and diagonal and off-diagonal cells correspond to correctly and incorrectly classified observations, respectively. \[\text{cm}=\text{confusionchart(Y,predictedY)}, \tag{8}\]  
\[\text{CM}=\text{cm.NormalizedValues}, \tag{9}\]  
The normalized confusion matrix (CM) provides a more interpretable view of the classification performance by showing the proportion of each predicted class relative to the actual class, which can be useful for comparing performance across different classes (9). Thus, in the proposed algorithm, the typology of the faults was structured as an array (the MonitoringArray) corresponding to the 12 functional states, each containing 41 functional parameters, described in Section 4. Algorithm testing, validation and updating were performed using test files obtained during the operation of the onboard installations, online or offline, during or after the trip was completed. Using kNN, we classify a new data point by analyzing and voting on the classes of the k closest points from the initial dataset and visualize the predictions in the confusion matrix chart created from the true labels and the predicted labels, and we compare the performance across different classes. In the end, the algorithm indicates the defects in order of their incidence. The GRAPH module allows a graphical representation of the operating data values according to the user option. The module serves as an essential tool for operational personnel to observe changes over time in monitored and calculated parameter values, functioning as an analysis instrument for failure modes in cases where the analysis report from the preceding module does not provide sufficient information for classification, when results are very close in value, or when necessary, analysis trends are not identified. Using data stored in the Monitoring Array matrix for monitored pressure and temperature parameters, the algorithm enables real-time or continuous two-dimensional (2D) displays of the target parameters throughout the recording period. The information is necessary to correlate the functional state of the components with the values of the operating data. The LINK_PMS module assists users in managing maintenance processes by providing relevant information on facility failures and displaying possible causes and remedial measures from FTA and FMECA analyses in a table format. It integrates with PMS on transport vessels to demonstrate the key features of the affected components and details of recent maintenance work.