A Multi-Stage Machine Learning Framework for Detecting Code Smells Using In-Depth Statistical Analysis
Keywords:
Software engineering, code smells, machine learning classifiers, ensemble learning, statistical validation, performance metrics.Abstract
Enhancing software quality is essential in development. Code smells indicating poor design can hinder maintenance and increase technical debt. This study introduces a nine-step machine learning framework that includes data preprocessing, feature engineering, model tuning, statistical validation, explainability through SHAP, and decision-making support for maintenance. It focuses on identifying Data Class and God Class smells using a project-level cross-project validation approach. Sixteen classifiers - ranging from probabilistic, instance-based, linear, tree-based, ensemble, to neural networks - were trained with object-oriented, size, and complexity metrics from open-source Java projects in the Qualitas Corpus and PROMISE repositories. Their performance measures included accuracy, precision, recall, F1-score, sensitivity, and AUC-ROC. Variations among classifiers were analysed with Shapiro-Wilk tests, ANOVA, Friedman's test, Kruskal-Wallis, Wilcoxon signed-rank, and Bonferroni pairwise comparisons. Ensemble methods consistently outperformed probabilistic and linear models; for instance, XGBoost reached 99.25% accuracy and 98.40% AUC-ROC, while Random Forest achieved a balanced F1-score of 97.65% alongside 98.40% accuracy. Statistical tests showed notable differences with moderate-to-large effect sizes, boosting confidence in the rankings. SHAP feature attribution revealed key object-oriented metrics influencing individual predictions, aiding refactoring prioritisation and technical debt triage. The framework is deliberately architected as a unified, extensible, and reproducible pipeline rather than an ad hoc combination of existing techniques, enabling additional code smells, languages, and industrial repositories to be incorporated without redesigning the underlying methodology. Overall, the study demonstrates that a statistically validated, explainable, multi-phase ensemble method effectively detects Data Class and God Class smells across projects, assisting refactoring and debt management. Future research will expand the framework to other code smells, larger external validation sets, and benchmark deep learning and graph models directly against these classifiers.





