Pneumonia diagnosis: chest X-ray
A convolutional neural network implementing automated interpretation of chest X-ray images to diagnose signs of pneumonia. The architecture and training methods reached figures that can be used in clinical work.
- Sector
- Machine learning, healthcare
- Role
- Researcher and developer
- Scope
- Data preparation, model architecture, training, evaluation
- Tools
- Python, TensorFlow, Keras, scikit-learn, NumPy, Pandas, Matplotlib, Seaborn, Pillow
- Dataset
- 5,863 X-rays, Guangzhou Women and Children’s Medical Center
- Year
- 2024-2025
Image size
A function was created to convert images to a single size of 128 by 128 pixels, and to check their format.
Balancing data
Undersampling was applied to bring the data sizes in NORMAL up to the sizes of PNEUMONIA, then combined into a balanced data frame.
Visualisation of results
The results show that the model reached a classification accuracy of 87.66% and a loss function value of 0.513, demonstrating good generalisation ability and stable performance.
Selecting a method for assessing the adequacy of learning outcomes
To evaluate the trained model objectively, a comprehensive approach was used covering both quantitative metrics and graphical analysis. That allows not only measuring overall accuracy, but understanding how well the model copes with each individual class - which matters under possible sample imbalance.
Experimental selection of network characteristics
To improve efficiency and reach higher generalisation ability, additional experimental modifications of the network configuration and training parameters were carried out. This stage was exploratory, aimed at identifying the most effective combinations of hyperparameters.
Model configuration
To test stability and the influence of optimiser choice on the learning process, the optimiser was replaced with Adam. An alternative strategy for managing retraining was also tested: instead of EarlyStopping, an adaptive adjustment of the learning rate - ReduceLROnPlateau - which avoids getting stuck in local optima and improves convergence.
Results
After implementing the Adam optimiser and the ReduceLROnPlateau strategy, the model improved significantly on key metrics. Total classification errors fell to 53 cases - 8% of the test sample - which is 13% better than the previous result.
The confusion matrix confirms the qualitative improvement: while maintaining high sensitivity to pneumonia (recall = 0.97), a significant minimisation of false diagnoses was achieved (precision = 0.95 for the NORMAL class).
Analysis of training adequacy
AUC = 0.97 indicates outstanding discriminatory ability. Cross-validation by 5 blocks showed the stability of the metrics, and testing on an independent sample confirmed the representativeness of the data.
The calibration curve demonstrates the adequacy of the probability estimates, which is critical for making clinical decisions. Analysis of the learning curves confirms that the model size corresponds to the size of the training sample (4,685 images).
The companion project is a stacked ensemble diagnosing dementia.