Pneumonia diagnosis: chest X-ray
A convolutional neural network that reads paediatric chest X-rays for signs of pneumonia – 0.97 recall and 0.97 AUC. A research model, built end to end during my degree, and honest about where it stops.
- Sector
- Machine learning, healthcare
- Role
- Researcher and developer – built end to end
- 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
Why I built this
I started this project after COVID-19, when the whole world saw how quickly a hospital can run out of people to read its scans. A model that flags likely pneumonia on a chest X-ray won’t replace a radiologist. But it can help one decide which image to look at first, and in a crowded ward that order can save lives.
I also wanted to work with image recognition myself. The same technology that reads an X-ray can sort, tag and understand visual content of any kind, so I see it opening doors well beyond healthcare, including in design.
Image size
Every image was resized to 128 × 128 pixels and checked for format before training.
Balancing data
The dataset holds far more PNEUMONIA images than NORMAL, so I oversampled NORMAL up to the size of PNEUMONIA and combined them into one balanced set.
First results
The first model reached 87.66% accuracy with a loss of 0.513 – a reasonable baseline, not a finished one.
How I evaluated it
Accuracy alone hides the failure that matters most here – a missed pneumonia. So I read precision and recall per class, the confusion matrix and the training curves together, rather than trusting one headline number.
Tuning
I then tested changes to the network configuration and training parameters, looking for the combination that generalised best rather than the one that scored best on training data.
Model configuration
Two changes made the difference: switching the optimiser to Adam, and replacing early stopping with ReduceLROnPlateau, which lowers the learning rate when validation loss stalls instead of ending training.
Results
Misclassifications fell to 53 – 8% of the test set. Recall for pneumonia stayed at 0.97, so the model still catches almost every positive case. Precision for NORMAL reached 0.95: when the model says an X-ray is clear, it is right 95% of the time.
Checking it holds up
AUC was 0.97. Five-fold cross-validation gave stable metrics across folds, the calibration curve showed the predicted probabilities can be read as probabilities – which matters if a clinician ever sees them – and the learning curves showed the model’s size suited its 4,685 training images.
Limits
This is a research model, not a clinical tool. The images come from one hospital – Guangzhou Women and Children’s Medical Center – and from children only, so it has not been tested on other scanners, other hospitals or adults. It would need external validation before it went anywhere near a patient. Knowing where a model stops working is the part of this I bring to designing any AI product.