Liliya Spencer.

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
Chest X-ray samples from the dataset

Image size

A function was created to convert images to a single size of 128 by 128 pixels, and to check their format.

Code and output for the image resizing function

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.

Class distribution before and after balancing

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.

Training and validation accuracy and loss curves

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.

Classification metrics table
Confusion matrix for the initial model

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.

Model configuration code
Revised training curves after the optimiser change

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).

Confusion matrix and metrics after optimisation

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.

Get in touch

Tell me what you’re building.

I’m open to a role where design owns something: the research behind it, the system underneath it, and the people doing the work. Singapore-based and a permanent resident here.