# An Empirical Evaluation of Ensemble Models for Python Code Smell Detection
## 3 Proposed Research Framework
### Data Selection
#### 3.1.6 Feature Selection Technique  
In this study, an FST was applied to select the best features from both datasets. In many studies, different types of FST (such as Recursive Feature Elimination (RFE) or Principal Component Analysis (PCA)) have been used. However, the chi-square technique was employed in this study. The characteristics and requirements of the dataset determined the choice to utilize chi-square FST. Chi-square is well-suited for categorical data and measures the independence between features and the target variable [14]. This is significant in this context because the features used to detect code smells, such as lines of code, comments, and complexity metrics, are treated as categorical in the feature selection process. Although these features are numerical in their raw form, they are discretized into categorical bins (e.g., low, medium, high) to facilitate the application of the chi-square test, which is most effective for categorical data. The Python code smell dataset comprises binary labels (smelly and non-smelly), rendering chi-square a logical and efficient selection. Generally, chi-square is more effective for small datasets, while the RFE is computationally intensive as it involves iteratively training models and ranking features. Given the dataset size and the need for computational efficiency, chi-square was a more practical choice. PCA focuses on dimensionality reduction by transforming features, which might reduce interpretability, as the transformed components are linear combinations of original features [32]. The chi-square FST maintains original feature names and structures, thereby ensuring interpretability, which is essential for identifying actionable insights in code smell detection [14]. To address potential bias, SMOTE was employed to balance the dataset, thereby ensuring robust and unbiased outcomes in feature selection.  
The chi-square FST used in this study is pivotal in enhancing the validity and performance of ensemble learning models. This FST strategy eliminates unnecessary features, retaining only the most significant ones. Chi-square FST is particularly effective in categorical datasets, as it includes relationships to aid in identifying the most valuable features [14]. Equation (2) demonstrates the chi-squared formula, a cornerstone of the feature selection process.  
\[X^{2}=\frac{(Observedfrequency-Expectedfrequency)^{2}}{Expectedfrequency} \tag{2}\]  
The observed frequency and expected frequency for the response and independent variables may be computed. The chi-square test determines how these two values differ from each other. Higher deviations lead to higher responses, indicating that the independent variables are interdependent.  
Figure 2: Confusion matrix for LC and LM dataset.  
Our analysis has identified the ten most precise features from each dataset. Table 2 displays these features, retrieved using the chi-square FST. The first feature has a high score, while the last has the lowest. The best 10 features out of 18 are selected with a keen eye on balancing model performance and simplicity. Focusing on these top 10 features reduces dimensionality, improves computational efficiency, and potentially enhances the model's generalization ability while retaining the most informative variables, contributing significantly to the predictive power. For a detailed understanding of these measures, please refer to Appendix A Table A1. Appendix A includes full descriptions of all selected measures.