# Evaluation of Artificial Intelligence-Based Models for Classifying Defective Photovoltaic Cells
## 2 Materials and Methods
### Methods
From this information, 28 variable candidates were calculated, as can be observed in Figure 3.  
\[C_{i}=(p_{i,0},...,p_{i,12768})\in\mathbb{R}^{12769},\,p_{i,j}\in\{0,1,...,255 \},\,0\leq i\leq 59,\,0\leq j\leq 12768\]  
- 1 st to 9 th variable \(\longrightarrow\) \(\mathrm{card}(\{p_{i,j}:25(k-1)\leq p_{i,j}<25k,0\leq j\leq 12768\}),\ \ 1\leq k\leq 9\)  
- 10 th variable \(\longrightarrow\) \(\mathrm{card}(\{p_{i,j}:225\leq p_{i,j}<256,0\leq j\leq 12768\})\)  
- 11 th to 19 th variable \(\longrightarrow\) \(P_{10\cdot(k-10)}(C_{i}),\ \ 11\leq k\leq 19\)  
- 20 th variable \(\longrightarrow\) \(P_{99}(C_{i})-P_{1}(C_{i})\)  
- 21 st variable \(\longrightarrow\) \(\sum_{j=0}^{12768}\,p_{i,j}\)  
- 22 nd variable \(\longrightarrow\) \(mean(C_{i})\)  
- 23 rd variable \(\longrightarrow\) \(var(C_{i})\)  
- 24 th variable \(\longrightarrow\) \(mode(C_{i})\)  
- 25 th variable \(\longrightarrow\) \(energy(C_{i})\)  
- 26 th variable \(\longrightarrow\) \(entropy(C_{i})\)  
- 27 th variable \(\longrightarrow\) \(kurtosis(C_{i})\)  
- 28 th variable \(\longrightarrow\) \(skewness(C_{i})\)  
Within the set of variables, the first 10 represent the number of pixels of any cell with values comprised in bands of length 25, except for the tenth variable that represents the number of pixels between 225 and 255. The next 9 variables represent the 9 percentiles ranging from the tenth percentile to the ninetieth percentile. The last 9 represent the range, the global sum of the 12,769 pixels, the mean, the variance, the mode, the energy, the entropy, the kurtosis, and the statistical skewness. Before deciding the variables with which to start the study, some requirements that influence their choice had to be taken into account. Mainly, it was sought to obtain the best global results, but it was also used to minimize the error in the classification of the elements related to group 3, that is, to avoid classifying elements from group 1 or 2 into group 3 and, vice versa. Since there could also be the possibility that there existed more than one variable that returned similar values for cells of opposite groups and therefore caused noise in the information, it was necessary to find and leave aside those variables. Figure 3: Pseudocode of the procedure for selecting the most significant variables. Given the difficulty of knowing which variables offer optimal results, the chosen strategy consisted of repeating the following method successively, previously standardizing all the data (60 cells explained in 28 variables) in mean 0 and variance 1. For this, 55 random cells were chosen 20,000 times. In the following paragraphs, the method is explained, and the proposed methodology for the selection of main variables are shown in Figure 4.  
1. Sample R such that \(5\leq\) R \(\leq\) 23 and randomly select R features: A random number R is obtained between 5 and 23. Next, R variables are chosen at random from among the 28 possible ones;
2. Principal Component Analysis (\(PCA\)) to Reduce dimensionality: Subsequently, principal component analysis is applied, saving the first variables that explain more than 99.5% of the variance of the data. Therefore, from now on, we work with 60 individuals explained in at most R new variables;
3. _KNN_ hyperparameter tuning from 200 random samples sized 55-training and 5-test, test _KNN_ with the best K on 20,000 random samples sized 55-training and 5-test: As we were interested in obtaining a good classification, the optimal number of neighbors \(k\) was sought, choosing between 1 and 10, starting from the one that offers the best results when applied in 200 random samples of size 55-training, 5-test. Once \(k\) has been obtained, the percentage of success with _KNN_ is now estimated from 20,000 random samples of size 55-training, 5-test. Finally, the proportion of bad classifications related to group 3 is noted. If the percentage of success with _KNN_ is less strict than 70%, step 1 becomes:
4.