# Predicting Software Cohesion Metrics with Machine Learning Techniques
###### Abstract  
The cohesion value is one of the important factors used to evaluate software maintainability. However, measuring the cohesion value is a relatively difficult issue when tracing the source code manually. Although there are many static code analysis tools, not every tool measures every metric. The user should apply different tools for different metrics. In this study, besides the use of these tools, we predicted the cohesion values (LCOM2, TCC, LCC, and LSCC) with machine learning techniques (KNN, REPTree, multi-layer perceptron, linear regression (LR), support vector machine, and random forest (RF)) to solve them alternatively. We created two datasets utilizing two different open-source software projects. According to the obtained results, for the LCOM2 and TCC metrics, the KNN algorithm provided the best results, and for LCC and LSCC metrics, the REPTree algorithm was the best. However, out of all the metrics, RF, REPTree, and KNN had close performances with each other, and therefore any of the RF, REPTree, and KNN techniques can be used for software cohesion metric prediction.  
software quality; CK metrics; software cohesion metrics; machine learning; LCOM +
Footnote †: journal: Medical  
LCOM3 [11], LCOM4 [12], LCOM5 [13], tight class cohesion (TCC), and loose class cohesion (LCC) [14]. The most used cohesion measurement metric is LCOM2 [8].  
In this study, LCOM2, TCC, LCC, and LSCC metric values were predicted by only using the number of methods (a procedure associated with a message and an object) and attributes. In order to calculate the cohesion value of a class, almost all of the metrics used in the literature considered the methods and attributes that form the basis of the class and their relationship with each other. The extent to which the variables created in a class are used by the methods created in that class directly affects the cohesion value of that class. In the cohesion metric formulas used, the number of methods and the number of attributes is necessarily common. They differ only in determining which situations the relationship between methods and attributes, which are the basic building block of the class, exist and in which situations they do not. Therefore, in this study, the number of methods and the number of attributes are used as independent variables, where these variables are common in other cohesion metrics and are the two main factors in determining the cohesion value of the class.  
While selecting the cohesion metrics, attention was paid to the different types of calculation features. All the selected cohesion metrics calculated the cohesion by considering different criteria and using different measurement techniques. The metrics used in this study were selected on the basis of the following properties:  
* LCOM2 is the most used cohesion metric;
* TCC metric uses the graph structure and is normalized;
* LCC considers not only direct connections, but also indirect connections;
* LSCC metric not only measures class cohesion but also measures the degree of cohesion.  
The dataset was not obtained ready-made, and it was produced within the scope of the study. LCOM2, TCC, LCC, and LSCC metric values of the classes were obtained with the help of the tool, and a dataset was created. By using machine learning methods, the values of the cohesion metrics were estimated with the least error.  
To the best of our knowledge, there is no study in the literature that predicts cohesion metrics using machine learning techniques.