Comparative Analysis of Random Forest and Convolutional Neural Network (CNN) Algorithms for Pneumonia Detection in Chest X-ray Images: Accuracy, Interpretability, and Computational Efficiency
Abstract
Pneumonia is a lung infection that can be detected through chest X-ray images. Manual diagnosis requires radiological expertise and time, thus an accurate automated method is needed. This study aims to compare the performance of two image classification algorithms, Convolutional Neural Network (CNN) and Random Forest (RF), in detecting pneumonia. The dataset used was obtained from Kaggle, consisting of 5,863 X-ray images categorized into three classes: bacterial pneumonia, viral pneumonia, and normal. Preprocessing steps include image resizing, normalization, and data augmentation. The CNN model was built using multiple convolutional and pooling layers, while RF utilized numerical features derived from histograms and texture. The CNN model demonstrated superior performance, achieving 92.4% accuracy, 93.1% precision, 91.6% recall, and 92.3% F1-score, compared to 82.7%, 80.3%, 85.1%, and 82.6% for Random Forest, respectively. Although CNN offers better accuracy, RF excels in interpretability. In conclusion, CNN is more effective for image-based pneumonia classification, yet RF remains relevant in applications requiring transparent decision-making. Potential biases, such as class imbalance and limited demographic representation in the dataset, could influence model performance and generalizability across different patient populations.
Downloads
References
World Health Organization, “Pneumonia in children.,” World Health Organization. Accessed: May 12, 2025. [Online]. Available: https://www.who.int/news-room/fact-sheets/detail/pneumonia
“Laporan Nasional Riskesdas 2018,” 2019.
P. Rajpurkar et al., “CheXNet: Radiologist-Level Pneumonia Detection on Chest X-Rays with Deep Learning,” Dec. 2017.
A. Esteva et al., “Dermatologist-level classification of skin cancer with deep neural networks,” Nature, vol. 542, no. 7639, pp. 115–118, Feb. 2017, doi: 10.1038/nature21056.
L. Breiman, Random Forests. 2001.
I. Md. D. Maysanjaya, “Klasifikasi Pneumonia pada Citra X-rays Paru-paru dengan Convolutional Neural Network,” Jurnal Nasional Teknik Elektro dan Teknologi Informasi, vol. 9, no. 2, pp. 190–195, May 2020, doi: 10.22146/jnteti.v9i2.66.
W. Liu, J. Zhang, and Y. Zhao, “A Comparison of Deep Learning and Traditional Machine Learning Approaches in Detecting Cognitive Impairment Using MRI Scans,” in 2022 IEEE 46th Annual Computers, Software, and Applications Conference (COMPSAC), 2022, pp. 998–1001. doi: 10.1109/COMPSAC54236.2022.00154.
N. Munnurukapu, R. Dillikar, B. Munnuru, and S. Naaz, “Predicting Pneumonia with Precision: A Deep Learning Approach,” Journal of Innovations in Data Science and Big Data Management, vol. 4, no. 1, pp. 10–25, Jul. 2025, doi: 10.46610/JIDSBDM.2025.v04i01.002.
S. L. Oh et al., “Classification of heart sound signals using a novel deep WaveNet model,” Comput Methods Programs Biomed, vol. 196, p. 105604, Nov. 2020, doi: 10.1016/j.cmpb.2020.105604.
J. G. Malaran and N. C. Pañares, “Multiple Intelligences Among Senior High School and Their Academic Performance,” INTERNATIONAL JOURNAL OF MULTIDISCIPLINARY RESEARCH AND ANALYSIS, vol. 08, no. 05, May 2025, doi: 10.47191/ijmra/v8-i05-03.
M. E. H. Chowdhury et al., “Can AI Help in Screening Viral and COVID-19 Pneumonia?,” IEEE Access, vol. 8, pp. 132665–132676, 2020, doi: 10.1109/ACCESS.2020.3010287.
M. T. Ribeiro, S. Singh, and C. Guestrin, “‘Why Should I Trust You?’: Explaining the Predictions of Any Classifier,” Aug. 2016.
D. S. Kermany et al., “Identifying Medical Diagnoses and Treatable Diseases by Image-Based Deep Learning,” Cell, vol. 172, no. 5, pp. 1122-1131.e9, Feb. 2018, doi: 10.1016/j.cell.2018.02.010.
R. R. Selvaraju, M. Cogswell, A. Das, R. Vedantam, D. Parikh, and D. Batra, “Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization,” Int J Comput Vis, vol. 128, no. 4, pp. 336–359, Dec. 2019, doi: 10.1007/s11263-019-01228-7.
J. Irvin et al., “CheXpert: A Large Chest Radiograph Dataset with Uncertainty Labels and Expert Comparison,” Proceedings of the AAAI Conference on Artificial Intelligence, vol. 33, no. 01, pp. 590–597, Jul. 2019, doi: 10.1609/aaai.v33i01.3301590.
E. Bisong, Building Machine Learning and Deep Learning Models on Google Cloud Platform. Berkeley, CA: Apress, 2019. doi: 10.1007/978-1-4842-4470-8.
Y. S. Nugroho and P. I. Santosa, “Penerapan Algoritma Random Forest pada Klasifikasi Citra X-ray Pneumonia,” Jurnal Teknologi Informasi dan Ilmu Komputer, vol. 7, no. 3, pp. 213–220, 2020.
A. Esteva et al., “A guide to deep learning in healthcare,” Nat Med, vol. 25, no. 1, pp. 24–29, Jan. 2019, doi: 10.1038/s41591-018-0316-z.
M. Toğaçar, B. Ergen, and Z. Cömert, “COVID-19 detection using deep learning models to exploit Social Mimic Optimization and structured chest X-ray images using fuzzy color and stacking approaches,” Comput Biol Med, vol. 121, p. 103805, Jun. 2020, doi: 10.1016/j.compbiomed.2020.103805.
M. Luqman, S. M. Anwar, and M. Rehman, “A Hybrid Approach Using CNN and Random Forest for Pneumonia Detection from Chest X-ray Images,” J Digit Imaging, vol. 35, pp. 505–514, 2022.
Bila bermanfaat silahkan share artikel ini
Berikan Komentar Anda terhadap artikel Comparative Analysis of Random Forest and Convolutional Neural Network (CNN) Algorithms for Pneumonia Detection in Chest X-ray Images: Accuracy, Interpretability, and Computational Efficiency
Pages: 1069-1077
Copyright (c) 2025 Siffa Zaena, Kemas Muslim Lhaksmana

This work is licensed under a Creative Commons Attribution 4.0 International License.
Authors who publish with this journal agree to the following terms:
- Authors retain copyright and grant the journal right of first publication with the work simultaneously licensed under Creative Commons Attribution 4.0 International License that allows others to share the work with an acknowledgment of the work's authorship and initial publication in this journal.
- Authors are able to enter into separate, additional contractual arrangements for the non-exclusive distribution of the journal's published version of the work (e.g., post it to an institutional repository or publish it in a book), with an acknowledgment of its initial publication in this journal.
- Authors are permitted and encouraged to post their work online (e.g., in institutional repositories or on their website) prior to and during the submission process, as it can lead to productive exchanges, as well as earlier and greater citation of published work (Refer to The Effect of Open Access).





















