journal article·2025-07-03Open access

An Empirical Evaluation of Ensemble Models for Python Code Smell Detection

Rajwant Singh Rao, Seema Dewangan, Alok Mishra

Applied Sciences· Volume 15· Issue 13

Abstract

Code smells, which represent poor design choices or suboptimal code implementations, reduce software quality and hinder the code maintenance process. Detecting code smells is, therefore, essential during software development. This study introduces a Python-based code smell dataset targeting two smell types: Large Class and Long Method. Five ensemble learning methods—Bagging, Gradient Boost, Max Voting, AdaBoost, and XGBoost—were employed to detect code smells within these datasets. The ten most significant features were selected using the Chi-square feature selection technique. To address the class imbalance, the SMOTE algorithm was applied. Experimental results yielded a best accuracy score of 0.96 and an MCC of 0.85 for the Large Class dataset using the Max Voting model. For the Long Method dataset, a best accuracy score of 0.98 and an MCC of 0.94 were achieved using the Gradient Boost model in conjunction with Chi-square feature selection. These results highlight the effectiveness of the proposed methodology and its potential to enhance code smell detection in Python significantly, reinforcing confidence in the approach’s thoroughness and applicability.
Source: crossref · Quality: baseline

Research context

OpenAlex topics: Software Engineering Research · Software Reliability and Analysis Research · Advanced Malware Detection Techniques

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

Affiliations

Department of Computer Science and Information Technology, Guru Ghasidas Vishwavidyalaya, Bilaspur 495009, Chhattisgarh, India

Faculty of Engineering, Norwegian University of Science and Technology (NTNU), 7034 Trondheim, Norway

Faculty of Logistics, Molde University College—Specialized University in Logistics, 6410 Molde, Norway

References (44)

Show source-provided references
1. Mining Version Histories for Detecting Code Smells10.1109/TSE.2014.2372760 ↗
2. Gervasi, O., Murgante, B., Misra, S., Borruso, G., Torre, C., Rocha, A., Taniar, D., Apduhan, B., Stankova, E., and Cuzzocrea, A. (2017, January 3–6). A Systematic Literature Review: Code Bad Smells in Java Source Code. Proceedings of the Computational Science and Its Applications–ICCSA 2017, Trieste, Italy.10.1007/978-3-319-62395-5 ↗
3. Python code smells detection using conventional machine learning models10.7717/peerj-cs.1370 ↗
4. Zazworka, N., Shaw, M.A., Shull, F., and Seaman, C. (2011, January 23). Investigating the impact of design debton software quality. Proceedings of the 2nd Workshop on Managing Technical Debt, Waikiki, HI, USA.10.1145/1985362.1985366 ↗
5. A survey on bad smells in codes and usage of algorithm analysis
6. Feature Reduction Techniques Based Code Smell Prediction
7. Improving accuracy of code smells detection using machine learning with data balancing techniques10.1007/s11227-024-06265-9 ↗
8. Decor: A method for the specification and detection of code and design smells10.1109/TSE.2009.50 ↗
9. A Severity Assessment of Python Code Smells10.1109/ACCESS.2023.3327553 ↗
10. Menshawy, R.S., Yousef, A.H., and Salem, A. (2021, January 26–27). Code smells and detection techniques: A survey. Proceedings of the 2021 International Mobile, Intelligent, and Ubiquitous Computing Conference (MIUCC), Cairo, Egypt.10.1109/MIUCC52538.2021.9447669 ↗
11. Mishra, A., Shatnawi, R., Catal, C., and Akbulut, A. (2021). Techniques for Calculating Software Product Metrics Threshold Values: A Systematic Mapping Study. Appl. Sci., 11.10.3390/app112311377 ↗
12. Bad smell detection using machine learning techniques: A systematic literature review10.1007/s13369-019-04311-w ↗
13. Machine learning techniques for code smelldetection: A systematic literature review and meta-analysis10.1016/j.infsof.2018.12.009 ↗
14. Dewangan, S., Rao, R.S., Mishra, A., and Gupta, M. (2022). Code smell detection using ensemble machine learning algorithms. Appl. Sci., 12.10.3390/app122010321 ↗
15. Code smells and refactoring: A tertiary systematic literature review10.1504/IJSSE.2024.135914 ↗
16. Vatanapakorn, N., Soomlek, C., and Seresangtakul, P. (2022, January 21–23). Python Code Smell Detection Using Machine Learning. Proceedings of the 2022 26th International Computer Science and Engineering Conference (ICSEC), Sakon Nakhon, Thailand.10.1109/ICSEC56337.2022.10049330 ↗
17. Code smell detection by deep direct-learning and transfer-learning10.1016/j.jss.2021.110936 ↗
18. Nunes, H.G., Santana, A., Figueiredo, E., and Costa, H. (2024, January 15–16). Tuning Code Smell Prediction Models: A Replication Study. Proceedings of the 46th International Conference on Program Comprehension (ICPC 2024), Lisbon, Portugal.
19. Code smell severity classification using machine learningtechniques10.1016/j.knosys.2017.04.014 ↗
20. Severity classification of software code smells using machine learning techniques: A comparative study10.1002/smr.2454 ↗
21. Code smell detection using feature selection and stackingensemble: An empirical investigation10.1016/j.infsof.2021.106648 ↗
22. Amorim, L., Costa, E., Antunes, N., Fonseca, B., and Ribeiro, M. (2015, January 2–5). Experience report:evaluating the effectiveness of decision trees for detecting code smells. Proceedings of the 2015 IEEE 26th International Symposium on Software Reliability Engineering (ISSRE), Gaithersburg, MD, USA.10.1109/ISSRE.2015.7381819 ↗
23. Tian, Y., Lo, D., and Sun, C. (2012, January 15–18). Information retrieval based nearest neighbor classification for fine-grained bug severity prediction. Proceedings of the 2012 19th Working Conference on Reverse Engineering, Kingston, ON, Canada.10.1109/WCRE.2012.31 ↗
24. Yadav, P.S., Dewangan, S., and Rao, R.S. (2021, January 1–2). Extraction of prediction rules of code smell using decision tree algorithm. Proceedings of the 2021 10th International Conference on Internet of Everything, Microwave Engineering, Communication and Networks (IEMECON), Jaipur, India.10.1109/IEMECON53809.2021.9689174 ↗
25. A Semisupervised Learning Approach for Code Smell Detection10.1007/s42979-025-03680-4 ↗
26. Finding bad code smells with neural network models
27. BDTEX: A GQM-based Bayesian approach for the detection of antipatterns10.1016/j.jss.2010.11.921 ↗
28. Vaucher, S., Khomh, F., Moha, N., and Gueheneuc, Y.G. (2009, January 13–16). Tracking Design Smells: Lessons from a Study of God Classes. Proceedings of the 16th Working Conference on Reverse Engineering, Lille, France.10.1109/WCRE.2009.23 ↗
29. Wang, X., Dang, Y., Zhang, L., Zhang, D., Lan, E., and Mei, H. (2012, January 3–7). Can I clone this piece of code here?. Proceedings of the 27th IEEE/ACM International Conference on Automated Software Engineering, Essen, Germany.10.1145/2351676.2351701 ↗
30. Mansoor, U., Kessentini, M., Bechikh, S., and Deb, K. (2023). Code-Smells Detection Using Good and Bad Software Design Examples, Land-grant University. Available online: https://www.egr.msu.edu/~kdeb/reports.shtml.
31. Optimizing Pre-Trained Code Embeddings with Triplet Loss for Code Smell Detection10.1109/ACCESS.2025.3542566 ↗
32. Rao, R.S., Dewangan, S., Mishra, A., and Gupta, M. (2023). A study of dealing class imbalance problem with machine learning methods for code smell severity detection using PCA-based feature selection technique. Sci. Rep., 13.10.1038/s41598-023-43380-8 ↗
33. Yavuz, A., and Kalıpsız, O. (2024, January 26–28). The Performance Analysis of Machine Learning Techniques in Code Smell Detection. Proceedings of the 2024 9th International Conference on Computer Science and Engineering (UBMK), Antalya, Turkiye.10.1109/UBMK63289.2024.10773525 ↗
34. Predicting the severity of open source bug reports using unsupervised and supervised techniques
35. An Evaluation of Multi-Label Classification Approaches for Method-Level Code Smells Detection10.1109/ACCESS.2024.3387856 ↗
36. Ray, B., Posnett, D., Filkov, V., and Devanbu, P. (2014, January 16–22). A large-scale study of programming languages and code quality in GitHub. Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering, Hong Kong SAR, China.10.1145/2635868.2635922 ↗
37. Rehef, K.K., and Abbas, A.S. (2024, January 14–15). Improving code smell detection using deep stacked autoencoder. Proceedings of the International Conference on Data Analytics & Management, London, UK.10.20944/preprints202403.1848.v1 ↗
38. Deep convolutional neural network model for bad code smells detection based on oversampling method
39. Chen, Z., Chen, L., Ma, W., and Xu, B. (2016, January 3–4). Detecting Code Smells in Python Programs. Proceedings of the 2016 International Conference on Software Analysis, Testing and Evolution (SATE), Kunming, China.10.1109/SATE.2016.10 ↗
40. Di Nucci, D., Palomba, F., Tamburri, D.A., Serebrenik, A., and De Lucia, A. (2018, January 20–23). Detecting code smells using machine learning techniques: Are we there yet?. Proceedings of the 2018 IEEE 25th International Conference on Software Analysis, Evolution and Reengineering (SANER), Campobasso, Italy.10.1109/SANER.2018.8330266 ↗
41. Yu, S., and Zhou, S. (2010, January 16–18). A survey on metric of software complexity. Proceedings of the 2010 2nd IEEE International Conference on Information Management and Engineering, Chengdu, China.10.1109/ICIME.2010.5477581 ↗
42. The Matthews correlation coefficient (MCC) is more informative than Cohen’s Kappa and Brier score in binary classification assessment10.1109/ACCESS.2021.3084050 ↗
43. Blagus, R., and Lusa, L. (2013). SMOTE for high-dimensional class-imbalanced data. BMC Bioinform., 14.10.1186/1471-2105-14-106 ↗
44. An empirical comparison of model validation techniques for defect prediction models10.1109/TSE.2016.2584050 ↗