# Pneumonia Disease Detection Using Chest X-Rays and Machine Learning
## 2 Methodology  
The deep learning algorithms chosen for the project are CNN and the pretrained model ResNet-50. CNN was considered due to its ability to recognize spatial hierarchies, capture details and patterns in chest X-rays, and effectively differentiate between normal and lung-infected chest X-rays. ResNet-50 has an architecture with 50 layers, trained on ImageNet. ResNet-50 was chosen for the research due to its deep architecture and ability to learn the features that are complex in the images.  
**Development Environment**  
The experiments were conducted using Python programming language, with libraries including TensorFlow and Keras because they provide excellent tools for deep learning models, Scikit-learn evaluation and splitting, Pandas for data manipulation and analysis, NumPy (np) for numerical operations, Matplotlib and Seaborn for visualization, and Pydicom for handling DICOM (medical imaging) data. The hardware set consists of an integrated entry-level consumer GPU and a specialized high-performing computing (HPC) system, which is an advanced GPU-enabled computing resource, \"VIPER\", designed for demanding computational tasks.  
The CNN models were developed with the original dataset and a reduced dataset of 5000 samples, with and without augmentation using CNN architecture, and then hyper-tuned using a Turner search to obtain the best results. The ResNet pretrained model was developed with the original data with augmentation and hyper-tuned for best results.  
_Dataset_  
The RSNA pneumonia detection challenge dataset consists of X-ray images and patient meta-data, publicly provided by the US National Institutes of Health Clinical Centre for a challenge [22]. The dataset was chosen because it has been successfully used for similar studies.  
The dataset comprises chest X-ray images (DICOM) from 26,684 unique patients. The classification file is made up of three categories built on the following image conditions:  
**No Lung Opacity/Not Normal**: no lung abnormalities detected;  
**Normal:** abnormalities unrelated to pneumonia;  
**Lung Opacity:** opacities that are visible, indicating pneumonia presence.  
The label file includes binary targets of \"1\" for pneumonia and '0' for non-pneumonia. The binary classification of \"1\" for pneumonia versus '0' for non-pneumonia was categorized as follows:  
**Pneumonia (1):** from Lung Opacity category;  
**Non-Pneumonia (0):** from No Lung Opacity and Not Normal and Normal categories.  
The distribution (as shown in Table 1) is as follows:  
**No Lung Opacity/Not Normal**--39.1%;  
**Normal**--29.3%;  
**Lung Opacity**--31.6%.  
Image meta-data were extracted and attributes such as patient sex, patient age, view position, and body part were examined with modality pixel spacing and integrated into the training data to improve pneumonia detection. A few sample images were viewed. Figure 2 displays string values converted to numeric values, which are essential for machine learning.  
The distribution of patient sex is '1' is 17,216 and '0' is 13,011. There was no need to balance the data. See Table 2. Age distribution that provided demographic characteristics to see possible effects on training was even. Correlations heat maps of the chosen meta-data were examined for the possible enhancement of the detection of pneumonia.