## 3 Methodology
#### Fault Detection Algorithm
To normalize the data presented in the graph, the domain (\(-\)100, 100) was utilized, and deviations from optimal parameters were measured as percentage values, where \(-\)100% and 100% denote negative and positive deviations, respectively, and 0 represents the optimal operation. This information is required to correlate the functional states of the components with the values of the operating data. Step 1. Initialize GraphData as MonitoringArray;  
Step 2. Determine the dimensions of GraphData and store them in variables  
m (rows) and n (columns);  
Step 3. Loop through each element of GraphData:  
- For each row index i from 1 to m:  
- For each column index j from 1 to n:  
a. If GraphData(i,j) == min_max(2,j):  
- Set DiagArray(i,j) to 0.  
b. Else if GraphData(i,j) \(<\) min_max(2,j) and \(\geq\) min_max(1,j):  
- Compute and set DiagArray(i,j) as follows:  
(\(-\)1 + (GraphData(i,j) \(-\) min_max(1,j))/(min_max(2,j) \(-\)  
min_max(1,j))) \(\times\) 100.  
c. Else if GraphData(i,j) \(>\) min_max(2,j) and \(\leq\) min_max(3,j):  
- Compute and set DiagArray(i,j) as follows:  
(GraphData(i,j) \(-\) min_max(2,j))/(min_max(3,j) \(-\)  
min_max(2,j)) \(\times\) 100.  
d. Otherwise,  
- Set DiagArray(i,j) to fault value. End the loops. The ANALYSIS module, having possible faults in the functional state as reference points, analyzes the provided dataset online or offline to determine the trend for each variable. The module extracts the time and variables provided by the sensors from the installation under test, sets a threshold for small variations and fits a linear model to each variable (3) to analyze, determine and display trends for each variable (5) based on a model (4). Thus, depending on the size of the database or the multitude of data provided by the sensors placed on board the ship, combining these techniques (kNN, ANN, CNN, PCA, EDM) based on the nature of the available data and resources, we can efficiently handle large-scale data with kNN. \[\text{mdl}=\text{fitl}(\text{time,sensors(:,i))};\] \[\text{Mdl}=\text{fitcknn(X,Y,'NumNeighbors',5,'Standardize',1)};\] \[\text{Mdl}=\text{fitcknn(X, Y,'Distance', 'cityblock')};\] \[\text{Mdl}=\text{KDTreeSearcher(import\_data); [idx, dist] = knnsearch(mdl, query Point, 'K', 5);\] [coeff, score] = pca(import\_data); reducedData = score(:, 1:k); % Keep top k principal components Mdl = fitcknn(reducedData, labels, 'NumNeighbors', 5); slope = mdl.Coefficients.Estimate, (4) trends[i] = determineTrend(slope,threshold), (5)  
Taking into account that our scenario dataset is small to moderately sized and low-dimensional and the fault classes are well-separated, for fault diagnosis, the kNN model is most suitable based on its simplicity and non-parametric nature, which makes it effective for real-time fault diagnosis and applications in which minimal assumptions about data distribution are required. The module trains a kNN classifier where the number of nearest neighbors in the predictors (k) is 5. The kNN model (Mdl) is created to classify data points based on the given features and labels and ensures that the numeric data are standardized to realize better performance (6). \[\text{Mdl}=\text{fitcknn(X,Y,'NumNeighbors',5,'Standardize',1)}, \tag{6}\]  
The predicted class labels are generated to evaluate the model's performance on the training set using trained regression models (7). Possible increasing or decreasing trends are translated into +1 and -1, respectively. A very small fluctuation is transferred to the value 0. Every possible failure mode of the system is characterized by a unique combination of trend values (+. 0, -1) of each monitored parameter. \[\text{predictedY}=\text{resubPredict(Mdl)}, \tag{7}\]  
A suitable ML technique for multi-class fault diagnosis depends on the specific characteristics of the dataset and the diagnosis requirements.