October 20, 2026
Pneumonia detection in X-ray images with a hybrid model of CNN and classifiers
Pneumonia Detection in X-ray Images with a Hybrid Model of CNN and Classifiers
Vitor Augusto Lemes Pinheiro dos Santos; Ricardo Janes
DOI: 10.22167/2675-6528-202603541
Article derived from a Course Conclusion Work (TCC), with content based on the student’s original work and adapted to the editorial format of the E&S Magazine with the support of the ResumeAI tool, an artificial intelligence solution developed by Instituto Pecege for textual synthesis and organization.
Summary
The detection of pneumonia in chest X-ray images has proven crucial for clinical diagnosis and for reducing risks associated with late disease identification. The objective was to develop and evaluate a hybrid model for the detection of pneumonia in chest radiographs. For this purpose, the BRAX dataset was used, which underwent selection, balancing, partitioning into training, validation, and testing, in addition to the application of data augmentation techniques. The VGG16 and ResNet50 architectures, pre-trained on ImageNet, acted as feature extractors with partial fine-tuning. These features were combined with Random Forest, XGBoost, and Support Vector Machine classifiers. Hyperparameter tuning was also performed with GridSearchCV to optimize the performance of the hybrid models. The results indicated consistent performance among the evaluated combinations. The hybrid VGG16 + XGBoost model stood out, presenting a precision of 0.650 and a recall of 0.950. It was concluded that the hybrid approach, combining pre-trained CNNs with classifiers, proved adequate for classifying normal cases and pneumonia cases, with data preparation and prioritization of recall being crucial for performance in medical applications.
Keywords: Transfer learning; Classifiers; Pneumonia detection; Feature extraction; Artificial intelligence.
1. Introduction
Pneumonia is characterized as an acute pulmonary infection that affects the pulmonary alveoli. The disease can be classified as community-acquired pneumonia or hospital-acquired pneumonia, depending on the site of acquisition. Its classification also considers the patient’s immunological status and the etiological agent, which are generally bacteria, viruses, or fungi (Lim, 2020).
Pneumonia represents a significant global health concern. According to the World Health Organization (WHO, 2025), the disease is among the leading causes of mortality worldwide, accounting for approximately fourteen percent of deaths in children under five years of age. In Brazil, pneumonia has been associated with a high number of annual hospitalizations and significant mortality rates (Ministry of Health, 2025). In this context, early diagnosis is fundamental for the effectiveness of treatment and the reduction of deaths.
Despite the importance of diagnosis, the analysis of chest radiographs by radiologists is a complex task that depends on professional experience. This dependence increases the probability of interpretation errors and diagnostic delays, especially due to high demand and scarcity of specialists (Ayan et al., 2021). The interpretation of radiographic images is intrinsically challenging due to the overlap of anatomical structures and the similarity between different pulmonary pathologies.
Faced with these challenges, Artificial Intelligence (AI) has emerged as a promising tool to support clinical decision-making. AI enables the development of automated systems for the detection and classification of respiratory diseases from X-ray images (Khan et al., 2021). Hybrid models based on Machine Learning (ML) and Deep Learning (DL) have shown promising results in the analysis of chest radiographs for pneumonia detection (Mustapha et al., 2025; Abueed et al., 2025; Akinbo et al., 2024).
Convolutional Neural Networks (CNNs), such as VGGNet and ResNet, are widely used as feature extractors in medical images (Varshni et al., 2019). These networks are often combined with supervised classifiers, such as Random Forest, XGBoost, and Support Vector Machine, for classification tasks (Sharma and Guleira, 2023). Furthermore, transfer learning is a technique that allows the use of pre-trained weights on large databases, optimizing training and improving the generalization capability of models on limited medical datasets (El Zein et al., 2021; Jain et al., 2020; Güler and Polat, 2022).
The need to improve the accuracy and efficiency in pneumonia diagnosis, mitigating the risks associated with delays in disease identification, justifies the search for innovative solutions. In this context, the work proposes the development and evaluation of a hybrid classification model for pneumonia detection in chest X-rays, using VGGNet and ResNet networks to extract features, combined with Random Forest, XGBoost, and Support Vector Machine algorithms in the classification stage to assist in diagnosis.
2. Material and Methods
The research was characterized as a case study, in which different learning models were applied to the same dataset (Aljuaid et al., 2026). The central objective was to develop and evaluate a hybrid model for the detection of pneumonia in chest X-rays, as proposed in the introduction.
The methodological approach comprised four main stages: data preparation, feature extraction, classification, and model evaluation. These phases were executed sequentially to ensure the construction and testing of the proposed system, detailing the model development process.
The study used the Brazilian Labeled Chest X-ray Dataset [BRAX], a database composed of 40,967 radiographic images. These images came from 24,959 studies of 19,351 patients, collected at the Hospital Israelita Albert Einstein, located in São Paulo, Brazil (Reis et al., 2022).
The image labels were derived from free-text radiological reports, originally written in Brazilian Portuguese. For the processing of these texts, Natural Language Processing [NLP] techniques were employed, with an adaptation of the “CheXpert” method for negation and uncertainty detection in the Portuguese language.
The choice of BRAX was based on its large volume of data and detailed documentation, which make it suitable for the development and validation of Machine Learning and Deep Learning models. The dataset was developed with a focus on the representativeness of the Brazilian population and patient privacy, ensuring anonymization and ethical inclusion criteria.
In the data preparation stage, initially, a CSV file was used containing the labeled data of each patient and the path to their respective images. The original dataset, which presented several disease classes, was filtered and converted to a binary format, containing only the normal and pneumonia classes.
Next, the dataset was balanced and divided into three subsets: training, validation, and testing. The split respected patient separation, preventing images from the same individual from appearing in different sets and causing overfitting.
The data distribution was 70% for training, 20% for validation, and 10% for testing. To deal with the class imbalance, especially the smaller number of samples in the pneumonia class, different balancing strategies were evaluated.
Three sampling strategies were investigated: manual undersampling, random undersampling with “RandomUnderSampler” [RUS], and oversampling with “Synthetic Minority Oversampling Technique” [SMOTE]. Manual undersampling was applied to all sets, reducing the majority class.
The RUS was employed only in the training set, removing samples from the majority class. SMOTE artificially generated new samples from the minority class through interpolation between existing examples and their nearest neighbors.
After comparing the balancing strategies, manual subsampling was selected for the subsequent steps, based on the “balanced accuracy score” metric. This approach showed the best average performance for binary classification problems on imbalanced datasets.
Additionally, data augmentation technique was applied to the training set. This technique generated synthetic images, increasing the number of available samples for training, which contributed to reducing overfitting and improving the model’s generalization capability (Dardouri, 2025).
The preprocessing parameters included resizing the images to 224 x 224 pixels, adjusting brightness (0.10) and contrast (0.20), and random horizontal flipping with a probability of 0.3. Image normalization was also performed using the default parameters from “ImageNet”.
For feature extraction, transfer learning was used with two convolutional neural networks [CNNs] pre-trained on “ImageNet”: ResNet50 and VGG16 (Manickam et al., 2021). These architectures served as feature extractors.
Both networks underwent partial fine-tuning, where most of the backbone remained frozen. The original classification layers were removed and replaced by a new linear head for binary classification, adapting the network to the specific problem (Varsho et al., 2019).
ResNet50, a deep architecture with 50 convolutional layers, employed residual blocks with shortcut connections. This structure allowed direct information flow between layers, preventing gradient vanishing and preserving relevant information during training (Sunil Kumar and Harish Kumar, 2023).
The output of ResNet50, after removing the original classification “Fully Connected” [FC] layer (FC 1000), resulted in a vector of 2048 features.
The VGG16 was composed of 13 convolutional layers and 5 “max pooling” layers, followed by 3 fully connected layers. This network is recognized for its simple and deep architecture, which provided robust extraction of feature vectors (Avola et al., 2022).
Similar to ResNet50, the VGG16 FC 1000 layer was removed. The output of VGG16, after this modification, generated a vector of 4096 features.
The classification stage used the features extracted by the CNNs as input for three supervised algorithms: Random Forest [RF], Extreme Gradient Boosting [XGBoost], and Support Vector Machine [SVM].
These classifiers were combined with the feature extractors to form the hybrid models, which performed the prediction of the presence of pneumonia or the normal condition.
Random Forest is an ensemble method based on multiple decision trees, which combines predictions to reduce variance and increase model robustness, being effective in medical data with noisy attributes (Brindha et al., 2024).
XGBoost is a decision tree-based “boosting” algorithm that optimizes the loss function additively, controlling model complexity and standing out for its high predictive accuracy (Rajeashwari and Arunesh, 2024).
The Support Vector Machine [SVM] seeks an optimal hyperplane to separate distinct classes in a high-dimensional space, minimizing structural classification errors, and is widely applied in binary tasks (Sourab and Kabir, 2022).
For each combination of feature extractor and classifier, the best hyperparameters were searched using “GridSearchCV”. The selection was based on the “scoring” strategy with F1 Score value for binary targets.
The evaluation of the models was performed based on widely used metrics in the machine learning literature applied to the medical field. The metrics obtained from the confusion matrix included accuracy, precision, recall (sensitivity), and F1 score (Al Mamlook et al., 2020; Géron, 2021; Grus, 2020).
Additionally, the “Receiver Operating Characteristic” [ROC] curve demonstrated the diagnostic capability of the binary classifier system, and the “Area Under the ROC Curve” [AUC-ROC] provided a scalar value that summarized the overall performance of the model across all classification thresholds.
Recall was prioritized in the evaluation, given the nature of the medical classification task. In chest X-ray examinations, failing to identify a true case of pneumonia (false negative) represents a more serious clinical error than misclassifying a healthy patient as sick.
For the processing of the models and the execution of the experiments, a computer equipped with the Windows 11 Operating System was used. The hardware configuration included an Intel i7-9700KF processor, 16 GB of RAM, and an NVIDIA GeForce GTX 1660Ti graphics processing unit [GPU] with 6 GB of VRAM.
The scripts developed for the data preparation, feature extraction, classification, and model evaluation stages were organized and commented in a public repository on GitHub. This repository aims to ensure the reproducibility of the study and a complete understanding of the methodological process.
3. Results and Discussion
The research results were presented and discussed in accordance with the outlined methodological steps, covering data preparation, feature extraction, classification, and model evaluation. This sequential organization allowed for a clear understanding of the project’s evolution and findings at each stage. For the execution of the models, a computational environment equipped with Windows 11, an Intel i7-9700KF processor, 16GB of RAM, and an NVIDIA GeForce GTX 1660Ti GPU with 6GB of VRAM was used, resources that supported the intensive processing of images and the training of algorithms.
Data preparation
The initial data preparation step involved using a CSV file that contained the labels for each patient and the paths to their respective radiographic images. The original dataset, named BRAX, presented several classes, including normal cases, pneumonia, and other lung pathologies. For the purpose of this study, the file was converted to a binary format, focusing exclusively on the “normal” and “pneumonia” classes, simplifying the proposed binary classification task.
After conversion, the dataset was balanced and split into training, validation, and test subsets. A crucial measure adopted was the separation of data by patient, ensuring that images from the same individual did not appear in different sets. This strategy was implemented to prevent model overfitting, ensuring that the generalization capability was evaluated more robustly and reliably, a fundamental aspect in medical applications.
The BRAX dataset revealed a significant imbalance between classes, with 29,009 images classified as normal and only 774 images of pneumonia. To mitigate this issue, the study explored three sampling strategies. The first was manual undersampling, which reduced the majority class to balance the proportion between classes across all datasets, resulting in 712 normal images and 538 pneumonia images for training, 213 normal and 156 pneumonia for validation, and 81 normal and 80 pneumonia for testing.
The second strategy consisted of random sampling, using the “RandomUnderSampler” (RUS) algorithm applied exclusively to the training set. This approach randomly removed samples from the majority class, maintaining the original distribution in the validation and test sets, which remained with 5799 normal images and 161 with pneumonia for validation, and 2814 normal and 75 with pneumonia for testing. The third strategy employed the “Synthetic Minority Oversampling Technique” (SMOTE) oversampling technique, which generated synthetic samples of the minority class through interpolation, increasing the diversity of the training data.
The comparison of balancing strategies was performed using the “balanced accuracy score” metric, which is particularly suitable for binary classification problems on imbalanced datasets. Manual undersampling demonstrated the best average performance, achieving 70.0% balanced accuracy. This result surpassed SMOTE, which obtained 67.2%, and RUS, with 65.5%, indicating that manual undersampling was the most effective approach for preparing the data for the subsequent steps of the hybrid model.
The preprocessing parameters applied to the training set included data augmentation and image normalization. The transformations involved resizing the images to 224 × 224 pixels, with a random crop scale between 0.85 and 1. Brightness (0.10) and contrast (0.20) adjustments were also applied using ColorJitter, and random horizontal flipping with a probability of 0.3. Normalization was performed with the mean ([0.485, 0.456, 0.406]) and standard deviation ([0.229, 0.224, 0.225]) parameters from “ImageNet”, which is crucial for the use of pre-trained networks and for improving the model’s generalization ability (Dardouri, 2025).
Feature Extraction
In the feature extraction phase, the study employed the transfer learning technique, using two convolutional neural networks (CNNs) pre-trained on “ImageNet”: ResNet50 and VGG16 (Manickam et al., 2021). Both architectures underwent partial fine-tuning, in which the original classification layers were removed, allowing the networks to act exclusively as feature extractors, following the approach of Varsho et al. (2019).
ResNet50, a deep architecture with 50 convolutional layers, integrated residual blocks with shortcut connections. This architectural configuration facilitated the direct flow of information between layers, preventing the vanishing gradient problem and preserving crucial information during training. This capability resulted in the extraction of high-quality features, as highlighted by Sunil Kumar and Harish Kumar (2023), contributing to the model’s robustness.
The VGG16, in turn, is composed of 13 convolutional layers and 5 “max pooling” layers, followed by 3 fully connected layers. This network is recognized for its relatively simple, yet deep architecture, which has proven effective in extracting robust feature vectors. VGG16 has been widely applied in medical radiographic classification tasks, as observed by Avola et al. (2022), due to its ability to capture complex visual patterns in images.
The partial fine-tuning of CNNs was monitored through the training loss (“train loss”) and validation loss (“val loss”) metrics. This monitoring allowed for the identification of the optimal convergence point for each network, preventing overfitting and ensuring that the model learned relevant data patterns. After this adjustment step, the temporary classification layer (“head”) was discarded, retaining only the contribution of the supervised fine-tuning in the network for feature extraction.
After fine-tuning, the images were processed by the VGG16 and ResNet50 CNNs, which functioned as feature extractors. The original “Fully Connected” (FC) classification layer, specifically FC 1000, was removed from both networks. With this modification, VGG16 generated a 4096-feature vector, while ResNet50 produced a 2048-feature vector, both representing the most relevant image attributes for pneumonia detection.
Classification
From the feature vectors extracted by CNNs, the study applied three supervised classification algorithms: Random Forest (RF), XGBoost, and Support Vector Machine (SVM). The combination of these feature extractors with the classifiers resulted in the formation of hybrid models, which were used to predict the presence of pneumonia or the normal condition in chest X-rays. This approach aimed to leverage the ability of CNNs to learn hierarchical image representations and the robustness of traditional classifiers.
For each combination of feature extractor and classification model, an exhaustive search for the best hyperparameters was performed using the “GridSearchCV” technique. This optimization was guided by the F1 Score as the “scoring” metric for binary targets, ensuring that the models were adjusted for an optimal balance between precision and recall, critical aspects in medical diagnostics. The hyperparameters optimized for VGG16 + RF included “class_weight”: “balanced”, “criterion”: “entropy”, “n_estimators”: 300, among others. For VGG16 + XGBoost, “n_estimators”: 600, “learning_rate”: 0.03, and “max_depth”: 4 stood out. For VGG16 + SVM, the main parameters were “clf C”: 1 and “clf_kernel”: “rbf”.
Similarly, the hyperparameters for the combinations with ResNet50 were also optimized. For ResNet50 + RF, “n_estimators”: 800 and “criterion”: “gini” were defined. In the case of ResNet50 + XGBoost, the parameters “n_estimators”: 1000, “learning_rate”: 0.01, and “max_depth”: 5 were the most relevant. For ResNet50 + SVM, the parameters “clf C”: 1 and “clf_kernel”: “rbf” were equally important. This detailed optimization ensured that each hybrid model operated at its maximum potential, adapting to the specificities of the data extracted by each CNN and the characteristics of each classifier.
Evaluation
The evaluation of hybrid models was performed based on widely recognized metrics in the literature of machine learning applied to the medical field, obtained from the confusion matrix. The metrics considered were accuracy, precision, recall (sensitivity), and F1 score (Al Mamlook et al., 2020; Géron, 2021; Grus, 2020). Recall was prioritized due to the nature of the medical classification task, where failing to identify a real case of pneumonia (false negative) is considered a more serious error than incorrectly classifying a healthy patient as sick, as a false negative can delay diagnosis and treatment, increasing clinical risks for the patient.
In general, the results demonstrated consistent performance between the two feature extractors, VGG16 and ResNet50, when combined with the evaluated classifiers. It was observed that the Random Forest and XGBoost classifiers achieved the best results in terms of recall, indicating their effectiveness in identifying positive cases of pneumonia. In contrast, the Support Vector Machine, although it presented higher precision values in some combinations, proved less effective in identifying positive cases, resulting in lower recall.
The hybrid VGG16 + XGBoost model stood out on the test set, presenting the highest recall, of 0.950, which means that 95% of real pneumonia cases were correctly identified. Furthermore, this model achieved the highest accuracy, of 0.720, and the best F1 score, of 0.772, with a precision of 0.650 and an AUC-ROC of 0.771. These results indicated that the combination of VGG16 for feature extraction with XGBoost for classification was the most effective for the pneumonia detection problem.
The analysis of the confusion matrix for the VGG16 + XGBoost model revealed that 140 cases of pneumonia were correctly identified (true positives), while only 16 cases of pneumonia were erroneously classified as normal (false negatives). This low number of false negatives confirmed the model’s high recall, indicating its ability to minimize the risk of missed diagnoses. However, the model also generated 106 false positives, classifying normal exams as pneumonia, which suggests that the model was more sensitive in detecting pneumonia than in recognizing normal cases.
The performance of the VGG16 + XGBoost model on the test set was corroborated by the Receiver Operating Characteristic (ROC) curve, which presented an Area Under the Curve (AUC) of 0.77. This value demonstrated a reasonable capability of the binary classifier system in distinguishing between images with and without pneumonia. Additionally, the Precision-Recall (PR) curve exhibited an Average Precision (AP) of 0.75, indicating a good overall balance between precision and recall. However, a reduction in precision was observed as recall increased, which implies a higher occurrence of false positives in scenarios requiring greater model sensitivity.
In summary, the study achieved the objective of developing and evaluating a hybrid model for the detection of pneumonia in chest X-ray images, combining pre-trained CNNs with classifiers. The adopted approach, which used CNNs as feature extractors associated with classic classification algorithms, proved to be adequate for classifying normal and pneumonia cases. The results indicated consistent performance among the evaluated hybrid models, with emphasis on the combinations based on XGBoost with VGG16 and ResNet50, which presented the best overall balance for the task, with data preparation and prioritization of recall being crucial for performance in medical applications.
4. Conclusion
The present study aimed to develop and evaluate a hybrid model for the detection of pneumonia in chest radiographs, combining pre-trained convolutional neural networks with traditional classifiers. It was found that data preparation, especially manual undersampling balancing, was crucial for the models’ performance. The VGG16 and ResNet50 architectures acted as feature extractors, and their combinations with Random Forest, XGBoost, and Support Vector Machine were evaluated. The hybrid VGG16 + XGBoost model stood out, presenting a recall of 0.950, accuracy of 0.720, F1 score of 0.772, and precision of 0.650. This high recall is particularly relevant in medical contexts, where minimizing false negatives is a priority to avoid delays in the diagnosis and treatment of pneumonia. The hybrid approach proved suitable for classifying normal and pneumonia cases, offering a diagnostic support system that can mitigate the challenges of manual interpretation of radiographic images.
The main contribution of this work lies in the development of a robust model that aids in the early diagnosis of pneumonia, focusing on reducing false negatives, which has direct implications for public health and treatment efficacy. However, the study faced limitations due to hardware constraints, which prevented the exploration of computationally more intensive approaches, such as more comprehensive cross-validation. Additionally, the low number of pneumonia cases in the original dataset limited the diversity of positive examples for training and evaluating the hybrid models. Overcoming these limitations in future studies can further enhance the generalization capability and clinical applicability of the proposed models.
Bibliographic References
Abueed, M. A. M. et al. (2025). Pneumonia Detection Using Transfer Learning: A Systematic Literature Review. International Journal of Advanced Computer Science and Applications (IJACSA), v.16
Abueed, M. A. M. et al. (2025). Pneumonia Detection Using Transfer Learning: A Systematic Literature Review. International Journal of Advanced Computer Science and Applications (IJACSA), v.16, n.2, p.1032–1045.
Ayan, E. et al. (2022). Diagnosis of Pediatric Pneumonia with Ensemble of Deep Convolutional Neural Networks in Chest X-Ray Images. Arabian Journal for Science and Engineering, v.47, p.2123–2139.
Khan, W. et al. (2021). Intelligent Pneumonia Identification from Chest X-Rays: A Systematic Literature Review. IEEE Access, v.9, p.51747–51763.
Ministério da Saúde. (2022). 12/11 – Dia Mundial da Pneumonia. Brasília: Ministério da Saúde.
Mustapha, B. et al. (2025). Enhanced Pneumonia Detection in Chest X-Rays Using Hybrid Convolutional and Vision Transformer Networks. Current Medical Imaging, v.21.
World Health Organization (WHO). (2021). Pneumonia in Children. Geneva: World Health Organization.
Article originating from the Final Course Project of the Specialization in Data Science and Analytics of the MBA USP/Esalq
To learn more about the course, click here and access the MBX Academy platform