## 3 Machine Learning and Fault Diagnosis
### Simple Fault Diagnosis Models
#### 3.4.3 k-Nearest Neighbor Algorithm (kNN)  
The kNN model is a method for classifying a new object by examining its distance from the nearest neighbor of training samples in feature space. It belongs to the family of supervised learning algorithms. This algorithm does not require learning strictly speaking but just focuses on storing the training dataset, hence the term lazy algorithm. Indeed, to predict the class of new input data, it will look for their k closest neighbors using the Euclidean or Manhattan distance or others in order to choose the class of the majority neighbors. Two voting schemes exist to determine a label namely, the majority vote assigned to the class that appears most commonly in its k-nearest neighbors and the weighted sum voting where each vote is weighted on the basis that the closer nearest neighbors must count more than distant neighbors [83]. As a result, the kNN classification model depends on three main determinants which are: the training samples, the distance between the training samples (labeled data) and the test samples (unlabeled data) and the value of k [95]. Figure 13 shows the working principle of the kNN model.  
Figure 12: Overview of SVM algorithm principle.  
Figure 13: Synoptic overview of the KNN algorithm.  
The kNN algorithm is straightforward and does not require training before making predictions. Its accuracy is not affected by adjusting several parameters or making additional assumptions [96]. It is also a versatile model that can be used to classify or regress and is suitable for sparse data [96]. Furthermore, this algorithm is threshold value independent and can detect small to medium data samples with high accuracy and speed, all while being relatively low cost compared to other existing methods such as DT and SVM [78; 97]. However, as the number of observations and independent variables increases, it can become slower. The effectiveness of the algorithm is limited by the fact that it only has access to one class of healthy operational data [98]. However, this problem can be avoided by only using data that are in optimal condition [99]. [PERSON] et al. used the KNN model to detect faults in the transmission line of a power system [79]. This model made it possible for all the cases tested to have a detection and classification accuracy of 100% [79]. Furthermore, a similar study made it possible to detect and classify all the possible faults of a six-phase transmission system [100]. Two new KNN-based diagnostic methods for classifying eight types of faults of a power transmission system yielded a success rate of 98% of detected faults [101]. Furthermore, [PERSON] et al. proposed the KNN model to detect and classify bypass diode, line-to-line and open-circuit faults in a PV system. The results generated from the simulated model and the experimental data present an accuracy of 98.7% [3]. This same KNN model was proposed from the experimental data to detect open circuit, line-to-line and partial shading faults to improve the results with an accuracy of 99.84% [102]. Also, a KNN model proposed to detect the open-circuit fault of an inverter using the output current and voltage of the inverter achieved good results with an accuracy of about 99.77% [103]. Similarly, [PERSON] et al. showed that among the machine learning models used for the detection of open circuit, short circuit, bypass diode shorted and inverter failure faults, only the KNN model achieved an accuracy of 100% against the SVM, DT and FL models [8].