# Predicting Software Cohesion Metrics with Machine Learning Techniques
## 4 Results and Discussion  
In this study KNN, RF, REPTree, LR, MLP, and SVM machine learning techniques were used for predicting software cohesion values. The results of the regression analysis were evaluated over the results of these techniques. In the study, the 10-fold cross-validation technique was used in all the models established. The training set given with this technique was divided into 10 equal parts. One in each cycle was used for testing, and the remaining nine were used for training. When the other cycle was passed, another part was used for testing, and the remaining nine parts were used for training. In this way, the same method was run 10 times using 10 different training and test sets. Since each split piece was used in both training and testing phases, the errors caused by the splits were minimized [32]. The analysis results obtained for the LCOM2 metric are given in Table 1.  
According to Table 1, it is seen that the lowest MAE value was obtained with the random forest algorithm. For the KNN algorithm, different k values were tried, starting from 1. As the k value was changed, the k value continued to be increased over odd numbers if the increase in the correlation coefficient and the decrease in the error rate continued. When the decrease started, the experiment was completed. For the LCOM2 \begin{table}
\begin{tabular}{l c c c c c c} \hline \hline  & \multicolumn{3}{c}{**Dataset\#1**} & \multicolumn{3}{c}{**Dataset\#2**} \\ \hline  & **R** & **MAE** & **RMSE** & **R** & **MAE** & **RMSE** \\ \hline REPTree & 0.937 & 23.067 & 105.718 & 0.947 & 18.675 & 53.308 \\ \hline RF & 0.973 & 18.938 & 71.253 & 0.968 & 16,385 & 41.561 \\ \hline KNN & 0.956 & 21.120 & 106.143 & 0.962 & 16,909 & 50.282 \\ \hline LR & 0.811 & 90.992 & 172.806 & 0.849 & 50,618 & 87.800 \\ \hline MLP & 0.982 & 23.813 & 56.555 & 0.955 & 32,170 & 51.887 \\ \hline SVM & 0.823 & 40.737 & 240.276 & 0.857 & 32.391 & 112.570 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Regression analysis results of LCOM2 metric. metric, the highest correlation coefficient and the lowest error value were obtained with the KNN algorithm at k = 3. The LCOM2 metric for Dataset#1 took values between 0 and 5749, and for Dataset#2, the LCOM metric took values between 0 and 2393. Therefore, outlier and extreme value analysis were performed on LCOM2 values. Equation (1) was used for outlier analysis and Equation (2) was used for extreme value analysis [33]. In the following formulas, Q3 is the third quartile, IQR is the interquartile range, EVF is the extreme values factor, and OF is the outlier factor. \[\text{Q3}+\text{OF}\times\text{IQR}<\text{x}\leq\text{Q3}+\text{EVF}\times \text{IQR} \tag{1}\]  
\[\text{x}>\text{Q3}+\text{EVF}\times\text{IQR}\text{ and x}<\text{Q1}-\text{EVF} \times\text{IQR} \tag{2}\]  
As a result of the extreme and outlier analysis, values in the range of 65 < x < 120 were determined as outliers and x > 120 were determined as extreme values for Dataset#1. For Dataset#2, the outlier range was 194 < x < 338, and extreme values were x > 338. The data for LCOM2's actual value which was in these ranges was extracted from the dataset. For Dataset#1, by discarding a total of 137 data, the study was repeated with the remaining 1052 data points. Similarly, for Dataset#2, 90 data points were discarded, and the study was repeated for 1147 data points. After extracting the data as a result of the outlier and extreme value analysis, the remaining data were retrained with the same machine learning techniques. The analysis results obtained after removing the outliers and extreme values are provided in Table 2.  
According to Table 2, the highest correlation and lowest error values were obtained with the KNN algorithm. The best results for KNN were obtained at k = 9. After removing the extreme values and outliers, the error rates decreased. After removing the extreme values, the same experiment was repeated by normalizing the LCOM2 metric between 0 and 1, and the result is shown in Table 3.