# An Empirical Evaluation of Ensemble Models for Python Code Smell Detection
## 5 Discussion
### Threats to Validity
#### 5.3.1 Internal Validity  
A principal threat to the internal validity of this study originates from the dataset itself. The dataset comprises a corpus of Python code smells with variables extracted from diverse code characteristics. This dataset offers a robust foundation; however, alternative or supplementary metrics may enhance the efficacy of identifying Python code smells. The code samples were selected based on criteria such as being written in Python, being open source, and being labeled as \"smelly\" or \"non-smelly\" using the PySmell dataset. Random sampling techniques were employed for data selection. Feature selection was conducted using the chi-square method to examine the relationship between the dependent variable (smelly or not) and the independent variables (code metrics). Only features  
\begin{table}
\begin{tabular}{l l l l l l l} \hline \hline \multirow{2}{*}{**Ensemble Learning Model**} & \multicolumn{3}{c}{**LC**} & \multicolumn{3}{c}{**LM**} \\ \cline{2-7}  & **Mean Accuracy** & **Standard Deviation** & \(p\)**-Value** & **Mean Accuracy** & **Standard Deviation** & \(p\)**-Value** \\ \hline Bagging & 0.93 & 0.02 & 0.01 & **0.98** & **0.01** & **0.04** \\ \hline Gradient Boost & 0.94 & 0.01 & 0.02 & **0.98** & **0.01** & **0.04** \\ \hline Max voting & **0.96** & **0.01** & **0.04** & 0.97 & 0.02 & 0.01 \\ \hline AdaBoost & 0.94 & 0.02 & 0.01 & 0.96 & 0.02 & 0.005 \\ \hline XGBoost & 0.93 & 0.03 & 0.002 & **0.98** & **0.01** & **0.04** \\ \hline \hline \end{tabular}
\end{table}
Table 10: Statistical Analysis. Bold values indicate the highest performance achieved among the ensemble methods.  
exhibiting a substantial gain ratio were incorporated in these experiments. The utilization of PySmell labels, grounded in expert assessment, may introduce subjectivity, thereby threatening validity. Furthermore, Chi-square analysis may produce erroneous results when the expected frequency of a characteristic is less than 5. A thorough analysis of the datasets verified that this condition was absent in the data utilized for this study, thus reassuring the absence of this limitation and the validity of this study's results.  
Despite being a popular tool for automated code smell detection, PySmell may not be able to detect some smells precisely because of rule-based limitations or misunderstandings of intricate code structures. Biases in feature extraction may result from this, especially if the labelled dataset contains false positives or false negatives.  
To address these concerns, a subset of the PySmell-labeled samples in the dataset was examined as part of an initial verification step. Although a fully manual validation process could further enhance the accuracy of the ground truth, the scalability of the dataset offers potential for future improvements in automated code analysis. The size of the dataset enables the possibility of incorporating manual validation for a larger proportion of samples. To improve dataset reliability, a hybrid strategy that combines automated detection with human validation is intended for future exploration.